使用常见问题
容器内时区问题
docker run
1
| docker run -v /etc/localtime:/etc/localtime:ro xxxx
|
docker-compose
1
2
| volume:
- /etc/localtime:/etc/localtime:ro
|
清理Docker系统中的无用数据
1
| docker system prune --volumes -f
|
安装docker
- 卸载旧的版本
1
2
3
4
5
6
7
8
| sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
|
- 设置仓库
1
2
3
| sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
|
- 设置阿里安装源
1
2
3
| sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
|
- 安装 Docker Engine-Community
1
| sudo yum install docker-ce-20.10.3-3.el7 docker-ce-cli-3:20.10.3-3.el7 containerd.io -y
|
- 启动docker
1
| sudo systemctl start docker
|
- 设置镜像加速
1
2
3
4
5
6
7
8
| sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2tgmzyyl.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
|
安装docker-compose
- 下载二进制文件
```
sudo curl -L “https://github.com/docker/compose/releases/download/1.28.4/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
1
2
3
|
# 安装docker-machine
- centos安装
|
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-uname -s
-uname -m
>/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
1
2
3
4
|
# 安装docker swarm
1. 初始化集群环境
- 使用内网ip即可
|
1
2
3
4
5
6
7
8
9
| docker swarm init --advertise-addr 10.31.149.124 ``` 2. 宿主机相同网络下的机器执行token即可加入swarm
1. 初始化网络生成从节点token, manager
```
docker swarm join-token manager
```
2. 初始化网络生成从节点token, worker
```
docker swarm join-token worker
``` 3. 同网络环境加入swarm,直接输入token即可 4. 加入swarm后,可使用 ``` docker node ls ``` 查看节点情况
|
- 正常情况下至少两主一从