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; 
相关推荐
小p8 小时前
docker学习: 2. 构建镜像Dockerfile
docker
小p1 天前
docker学习: 1. docker基本使用
docker
崔小汤呀1 天前
Docker部署Nacos
docker·容器
缓解AI焦虑1 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
1candobetter2 天前
Docker Compose Build 与 Up 的区别:什么时候必须重建镜像
docker·容器·eureka
シ風箏2 天前
MySQL【部署 04】Docker部署 MySQL8.0.32 版本(网盘镜像及启动命令分享)
数据库·mysql·docker
BugShare2 天前
继《小爱音响》详细说下怎么部署,尤其是关于Docker部分
docker·nas·xiaomusic
小马爱打代码2 天前
Docker:完全指南从入门到精通
运维·docker·容器
ITKEY_2 天前
docker 容器端口映射消失
docker·容器