docker compose 的安装和入门实战
compose说明
- 原生docker命令操作容器比较麻烦
- compose可以把操作容器的命令写入到配置文件中,让我们更方便的操作容器
compose的安装
yum install python-pip -y pip install docker-compose pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ docker-compose docker-compose version
compose配置文件:/docker/compose/redis/docker-compose.yml
version: ‘2‘ services: redis: image: centos7:redis
compose操作容器
- 后台启动容器:docker-compose up -d
- 查看容器:docker-compose ps
- 停止并删除容器:docker-compose down
- 停止启动容器:docker-compose stop; docker-compose start
docker-compose exec的使用
docker-compose exec nginx bash
compose管理多个容器docker-compose.yml
version: ‘2‘ services: redis: image: centos7:redis nginx: image: centos7:nginx
compose使用端口映射
version: ‘2‘ services: redis: image: centos7:redis ports: - "6379:6379" nginx: image: centos7:nginx ports: - "8080:80" - "9090:80"
compose设置网络模式
version: ‘2‘ services: redis: image: centos7:redis nginx: image: centos7:nginx network_mode: "host
compose设置文件共享
version: ‘2‘ services: nginx: image: centos7:nginx network_mode: "host" volumes: - /centos7/logs:/usr/local/nginx/logs - /centos7/apps:/usr/local/nginx/html/apps
compose同个镜像启动多个容器
- docker-compose up -d --scale redis=3
- docker-compose exec --index=2 redis bash
相关推荐
afanti 2020-09-14
链块学院 2020-11-06
白开水 2020-07-19
liyansring 2020-07-18
shenzhenzsw 2020-07-18
啦啦啦啦啦 2020-06-28
yangliuhbhd 2020-06-12
小爷有点狂 2020-06-12
无风的雨 2020-06-12
changecan 2020-06-11
蒜蓉粉丝蒸扇贝 2020-06-10
lihongtai 2020-06-08
liaochaowu 2020-06-06
zwt00 2020-06-05
scmrpu 2020-06-02
kuzilala 2020-05-14
小信 2020-05-14