Docker Swarm 集群

swarm
指定副本数,服务运行节点数
–replicas 3

docker service update
更新docker service
–update-delay 设置延迟时间
–update-parallelism 并行更新数
–update-failure-action 失败后行为
–update-max-failure-ratio 失败比例
–update-monitor 更新监控时间

–rollback 回滚

Docker Portainer 容器管理工具

portainer 持久化

数据文件夹
/home/portainer/data

1
2
volumes:
- /home/portainer/data:/data

Docker Nginx 安装

1
2
3
4
5
6
7
docker run -d --name nginx \
-v /usr/share/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
-v /usr/share/nginx/html:/usr/share/nginx/html:ro \
-v /usr/share/nginx/log:/var/log/nginx \
-p 80:80 \
--restart=always \
nginx

简化版:

1
docker run -d --name nginx -p 80:80 daocloud.io/library/nginx:latest

Docker Ghost 安装

Ghost

Ghost 是基于 Node.js 的开源博客平台,目的是为了给用户提供一种更加纯粹的内容写作与发布平台。

启动命令:

1
docker run -d -name ghost -p 80:2368 -v /root/ghost/data:/var/lib/ghost/content ghost

释义:

1
2
3
4
5
docker run -d \ #创建一个后台运行容器,并返回容器ID
--name ghost \ #为容器指定一个名称
-p 80:2368 \ #将容器的80端口映射到主机的80端口
-v /root/ghost/data:/var/lib/ghost/content \ #主机的目录/root/ghost/data映射到容器的目录/var/lib/ghost/content
ghost #使用docker官方镜像ghost:latest

参考

Ghost
Ghost中文网

Docker compose file 配置参考

示例配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: "3"
services:

redis:
image: redis:alpine
ports:
- "6379"
networks:
- frontend
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure

db:
image: postgres:9.4
volumes:
- db-data:/var/lib/postgresql/data
networks:
- backend
deploy:
placement:
constraints: [node.role == manager]

networks:
frontend:
backend:

volumes:
db-data:
  • version:
  • services:

deploy - 应用发布配置

restart_policy - 应用发布重启策略

1
2
3
4
5
6
7
8
9
10
version: "3"
services:
redis:
image: redis:alpine
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
  • condition: 可选项 none on-failure any(default)
  • delay: 尝试重启等待时间,默认0s
  • max_attempts: 最大重启次数,默认无限,首次启动不计入
  • window: 判定重启是否成功等待时长,默认0s

update_config - 应用发布更新策略

1
2
3
4
5
6
7
8
9
10
11
12
version: '3.4'
services:
vote:
image: dockersamples/examplevotingapp_vote:before
depends_on:
- redis
deploy:
replicas: 2
update_config:
parallelism: 2
delay: 10s
order: stop-first

官方参考文档地址:

Docker 镜像清理

1
2
3
4
5
6
7
8
9
10
# 删除所有 Docker 镜像
docker rmi $(docker images -f "dangling=true" -q)
# 删除所有未运行 Docker 容器
docker rm $(docker ps -a -q)
# 删除所有未打 tag 的镜像
docker rmi $(docker images -q | awk '/^<none>/ { print $3 }')
# 删除所有镜像
docker rmi $(docker images -q)
#根据格式删除所有镜像
docker rm $(docker ps -qf status=exited)

Docker镜像下载加速器

配置DaoCloud加速器:

1
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://b18c7aa2.m.daocloud.io

配置阿里云加速器:

1
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s https://zf0ry6xq.mirror.aliyuncs.com

查看加速配置信息:

1
docker info

配置完成后需要重启docker服务:

1
systemctl restart docker

1
service docker restart

Docker 安装

系统:CentOS系统

安装

脚本方式:

1
curl -fsSL https://get.docker.com/ | sh

可选用阿里镜像站点安装:参考 https://yq.aliyun.com/articles/110806

1
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

centos命令

1
2
3
4
service docker start
service docker stop
service docker status
service docker restart

docker命令

1
2
3
4
5
6
docker ps
docker images
docker rm #{container_id}
docker rmi #{image_id}
# 进入运行中的容器
docker exec -it d48b21a7e439 /bin/sh # d48b21a7e439 - 容器id,container_id
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×