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; 
相关推荐
Meaauf7 小时前
Registry私有容器镜像仓库搭建
docker·容器·registry
always20228 小时前
AI Infra · 02 - AI 感知的任务调度:Gang Scheduling、拓扑感知与潮汐弹性
人工智能·docker·kubernetes
Monkey的自我迭代11 小时前
K8S详细学习1——为什么选择k8s
学习·docker·kubernetes
zjeweler12 小时前
Nginx 502 Bad Gateway怎么解决?Docker反代与PHP-FPM报错全链路排查
nginx·docker·php-fpm·502 bad gateway·实用建站
木雷坞1 天前
n8n Docker 读不到 CSV,先分清宿主机目录和容器路径
java·docker·容器
有风听风有雨看雨1 天前
MinIO 单节点Docker(密码放配置文件)
运维·docker·容器
长不大的杨瑞杰1 天前
Kubernetes CrashLoopBackOff 排障全流程:OOM、探针、应用退出与依赖故障定责
docker·云原生·容器·kubernetes·devops·oomkilled
车软学堂1 天前
Docker在隔离什么:namespace、cgroup、chroot三道墙
linux·python·docker·容器·车载系统·汽车·测试用例
方便面不加香菜1 天前
Docker 网络原理 -- 常见的网络虚拟化
网络·docker·容器
芯飞云1 天前
8核16G云服务器到手后,用Docker Compose跑一个完整服务栈
运维·服务器·docker