For AI agents: the complete documentation index is available at https://www.tteam.icu/llms.txt, the full documentation bundle is available at https://www.tteam.icu/llms-full.txt, and this page is available as Markdown at https://www.tteam.icu/blog/ops/%E3%80%90%E5%AE%9E%E7%94%A8%E7%9A%84docker%E5%B0%8F%E6%8A%80%E5%B7%A7%E3%80%91%E9%83%A8%E7%BD%B2docker.md.

Docker部署指南

以CentOS 7为例

安装Docker

# 更新yum包
yum update -y
# 安装Docker
yum install -y docker
# 启动Docker
systemctl start docker                                                          
# 设置Docker开机自启
systemctl enable docker

实用技巧

设置容器开机自启

如果运行容器时忘记设置开机自启,可以执行:

docker update --restart=always 容器名或者ID

使用主机网络

--net=host

更换阿里云镜像源

编辑配置文件:

vi /etc/docker/daemon.json

添加以下内容:

{"registry-mirrors": ["https://pee6w651.mirror.aliyuncs.com"]}

安装Docker Compose

sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose