Docker常见操作

  • 打包(记得最后面的.不能少了
powershell 复制代码
 docker build -t lab:latest .
  • 运行
powershell 复制代码
 docker run -d -p 8888:8080 myproject 
  • 进入容器
powershell 复制代码
 docker exec -it 容器名称 bash
  • 查看docker实例日志
powershell 复制代码
 docker logs 实例id
  • 查看正在运行的docker容器
powershell 复制代码
 docker ps  
  • 查看所有正在运行的docker容器
powershell 复制代码
 docker ps -a
  • 查看docker镜像
powershell 复制代码
 docker images
  • 停止docker容器实例
powershell 复制代码
 docker stop 容器id
  • 删除docker容器
powershell 复制代码
 docker rm 容器id
  • 删除docker镜像
powershell 复制代码
 docker rmi 镜像id
  • 部署Java
  1. 将xxx.jar和Dockerfile文件放在一个目录下
  2. 通过命令行打包成docker镜像(记得最后面的.不能少了
powershell 复制代码
 docker build -f Dockerfile -t xxx:1.0 .
  1. 启动镜像
powershell 复制代码
 docker run  --net=host --name xxx -p 8080:8080 -d xxx:1.0
  • 停止wsl方法
powershell 复制代码
wsl --shutdown
  • docker部署mysql服务
  1. 命令行拉取mysql镜像
powershell 复制代码
docker pull mysql
  1. 查看是否拉取成功
powershell 复制代码
docker images mysql:latest
  1. 运行mysql镜像,启动mysql实例
powershell 复制代码
docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD="root" -d mysql:latest

注意:3306:3306前面的是mysql在windows里端口,后面的是mysql在docker里端口,如果windows外面安装了mysql,端口也是3306,那么要先关闭windows的mysql,不然会有端口冲突

解决办法:管理员运行cmd,输入以下命令停止mysql服务

powershell 复制代码
net stop mysql
  1. 进入容器内部 docker exec -it 容器id /bin/bash
powershell 复制代码
docker exec -it 5c5d73017b6c /bin/bash
  1. 登陆mysql
    出现root@容器id:/# 代表进入成功,接着输入账号密码
powershell 复制代码
mysql -u root -p

6.修改新密码并设置远程连接

powershell 复制代码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
// 刷新权限
flush privileges; 
相关推荐
孙克旭_6 小时前
Docker 镜像构建|Vue+SpringBoot+Go 多语言项目 Dockerfile 案例
linux·运维·vue.js·spring boot·docker·dockerfile
JavaPub-rodert8 小时前
使用 Docker 部署 Ollama:Docker Compose 一键运行 DeepSeek-R1 1.5B
运维·docker·容器
二宝哥11 小时前
docker安装apisix
docker·容器·apisix
ylj_dev15 小时前
从 0 构建 AI Workload Platform(四):从单机工作流内核到可靠控制面
docker·postgresql·架构·golang
.柒宇.16 小时前
使用 cri-docker 搭建 Kubernetes 集群完整教程(v1.36.3)
docker·容器·kubernetes·k8s集群安装
艾伦_耶格宇18 小时前
【DOCKER容器实战】-3 ElasticSearch + Kibana
elasticsearch·docker·jenkins
海兰18 小时前
【 Kafka进阶5】使用 Docker 部署 Apache Kafka 集群完全指南
docker·kafka·apache
sel_919 小时前
【Docker】Docker 安装与使用详解:从零搭建到日常实战
人工智能·深度学习·算法·docker
卷无止境1 天前
Windows 上丝滑开发 Python,并稳定构建 Docker 镜像
后端·python·docker
吕海洋1 天前
目前可用的docker源2026.08
运维·docker·容器