Docker 常用命令

Volume

查看容器的 volume
  • sudo docker inspect mysql | grep Mounts -A 10

Logs

查看容器日志
  • sudo docker logs mysql 2>&1 | grep PASSWORD

Docker 本身

安装 Docker
  • sudo apt-get update
  • sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • sudo apt-key fingerprint 0EBFCD88
  • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
  • sudo apt-get update
  • sudo apt-get install docker-ce docker-ce-cli containerd.io
  • sudo docker run hello-world
查看 docker 本身的信息
  • sudo docker info

MySQL

获取 mysql 镜像
  • sudo docker pull mysql/mysql-server
启动 mysql 容器
  • sudo docker run --name=mysql --restart on-failure -d mysql/mysql-server
  • sudo docker run -p 3306:3306 --name mysql -d mysql/mysql-server
从容器里面链接到 mysql
  • sudo docker exec -it mysql mysql -uroot -p
把密码改了
  • ALTER USER 'root'@'localhost' IDENTIFIED BY 'Jiangdi_2018';;
让 mysql 可以从宿主机访问
  • CREATE USER 'root'@'%' IDENTIFIED BY 'Jiangdi_2018';
  • grant all privileges on *.* to 'root'@'%';;
进入容器
  • sudo docker exec -it mysql bash

你可能感兴趣的:(Docker 常用命令)