Docker 服务管理
- 启动服务:
sudo systemctl start docker
- 停止服务:
sudo systemctl stop docker
- 重启服务:
sudo systemctl restart docker
- 查看状态:
sudo systemctl status docker
- 开机自启:
sudo systemctl enable docker
- 禁用自启:
sudo systemctl disable docker
容器基本操作
- 运行容器:
docker run
可选择交互式-it
或后台运行-d
- 指定名称:
--name [container-name]
- 端口映射:
-p [host-port]:[container-port]
- 暴露端口:
--expose [container-port]
- 挂载卷:
-v [host-dir]:[container-dir]
或--mount type=bind,source=[host-dir],target=[container-dir]
- 设置环境变量:
-e [env-var]=[value]
或--env-file [file-path]
- 连接网络: