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; 
相关推荐
灯澜忆梦5 小时前
【minio】#1 | 简介与安装
docker·对象存储·minio
江湖有缘15 小时前
3款开源绘图工具整理合集,可Docker一键部署!
docker·容器·开源
TTATTC15 小时前
告别协议选型内耗:深入拆解微服务“内部 gRPC + 边界 REST”混合通信架构与 Envoy 转码实战
docker·开源
光依旧1 天前
PageIndex没翻车,翻车的是我的解析器
docker·langchain·大模型·向量数据库·pdf解析·rag·pageindex
谢亮_vipxieliang2 天前
容器排障实战手册:从日志到内核的分层排障
docker·云原生·容器·eureka
梦想不只是梦与想2 天前
Docker 常用命令
docker
小白的码BUG之路2 天前
Docker -- 构建ruoyi-gateway镜像
docker·容器·gateway
小白的码BUG之路2 天前
Docker -- 构建ruoyi-system镜像
运维·docker·容器
小白的码BUG之路2 天前
Docker -- 构建redis镜像
运维·docker·容器
江湖有缘2 天前
Docker实战 | 使用Docker部署EspoCRM开源客户关系管理平台
docker·容器·开源