1.开机自启动
sudo systemctl enable docker
2.运行/停止/重启/查看docker环境
sudo systemctl start docker
sudo systemctl stop docker
sudo systemctl restart docker
sudo systemctl status docker
3.创建并运行一个docker容器
sudo docker run hello-world
sudo docker run -it --name=my_ubuntu_container ubuntu /bin/bash
-it:交互式启动
--name:容器名字为my_ubuntu_container
image镜像:ubuntu
command:/bin/bash
4.列出正在运行/所有的docker容器
sudo docker ps
sudo docker ps -a
5.启动/进入容器(exit退出容器,但容器不会关闭)
sudo docker start 容器名或ID
sudo docker exec -it 容器名或ID /bin/bash
6.停止/删除一个docker容器
sudo docker stop container_id/names
sudo docker rm container_id/names
7.从docker hub拉取镜像
sudo docker pull 镜像名字
8.列出本地所有的docker镜像
sudo docker images
9.删除一个docker镜像
sudo docker rmi image_id
10.构建一个docker镜像
sudo docker build -t image_name .
11.将Docker容器的数据备份到本地
sudo docker commit container_id repository/image_name:tag
12.将Docker镜像推送到Docker Hub
sudo docker push repository/image_name:tag
13.保存容器更改并转换成新的镜像
docker commit my_ubuntu_container my_custom_ubuntu_image
14.导入导出容器
sudo docker export 容器ID > 文件名.tar
cat 文件名.tar | docker import - 镜像用户/镜像名:镜像版本号
(cat ubuntu.tar | docker import - ubuntu:1.0.0)