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; 
相关推荐
wudl556620 小时前
Docker 常用命令
docker·容器·eureka
选与握1 天前
ubuntu22 docker安装ros1 noetic
docker·ros1
wuyunhang1234561 天前
Docker----快速入门
docker·容器·架构
liliangcsdn1 天前
docker环境如何基于python操作mysql关系数据库
docker·容器
java_logo1 天前
Docker 部署微服务项目保姆级教程
java·运维·docker·微服务·容器·eureka·架构
冲上云霄的Jayden1 天前
修改 Docker 容器中 MySQL 8.0 默认编码为 utf8mb4_unicode_ci
utf-8·mysql·ci/cd·docker·utf8mb4
zwjapple1 天前
react+springboot的Docker部署
docker·部署·springboot·react
遇见火星1 天前
Docker入门:快速部署你的第一个Web应用
前端·docker·容器
浪飘1 天前
k8s device plugin
java·docker·kubernetes
冬夜戏雪1 天前
milvus容器restart不成功,但docker仍在running问题排查
docker·容器·milvus