docker-compose管理容器

docker-compose管理容器

一、下载docker-compose

1.下载依赖

执行命令:

curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

2. 给下载目录授予权限

chomod 777 /usr/local/bin/docker-compose

验证docker-compose是否安装成功

docker-compose –v

二、创建docker-compose.yaml配置文件

1.在root目录下创建一个docker-compose的目录

cd /root

mkdir docker-compose

touch docker-compose.yml

添加以下配置:

version: '3'

services:

mysql:

image: mysql:5.7

privileged: true

ports:

- 3306:3306

environment:

- MYSQL_ROOT_PASSWORD=Testfan#123

volumes:

- /root/docker/mysql/conf/my.cnf:/etc/mysql/my.cnf

- /root/docker/mysql/data:/var/lib/mysql

networks:

- mtx

redis:

image: redis

privileged: true

ports:

- 6379:6379

volumes:

- /root/docker/redis/conf/redis.conf:/etc/redis/redis.conf

networks:

- mtx

command: redis-server /etc/redis/redis.conf

tomcat-pinter-1:

image: tomcat:8.5.0-jre8

privileged: true

ports:

- 8080:8080

volumes:

- /root/docker/tomcat/webapps:/usr/local/tomcat/webapps

networks:

- mtx

depends_on:

- mysql

- redis

tomcat-pinter-2:

image: tomcat:8.5.0-jre8

privileged: true

ports:

- 8090:8080

volumes:

- /root/docker/tomcat/webapps:/usr/local/tomcat/webapps

networks:

- mtx

depends_on:

- mysql

- redis

nginx:

image: nginx

privileged: true

ports:

- 80:80

volumes:

- /root/docker/nginx/conf.d:/etc/nginx/conf.d

- /root/docker/nginx/logs:/var/log/nginx

networks:

- mtx

depends_on:

- tomcat-pinter-1

- tomcat-pinter-2

networks:

mtx:

driver: bridge

2.关闭以前启动的容器

docker stop 84c4fa341d62

docker stop 4672429de27b

docker stop de5032a8efd7

docker stop 8ddf607e7359

docker stop 52b94a9fb918

3.在docker-compose.yml同级目录下启动

docker-compose up –d

4.浏览器中检查是否可以访问

5.docker-compose其他命令

后台启动容器:docker-compose up -d [容器名]

停止并删除容器:docker-compose down [容器名]

停止容器:docker-compose stop [容器名]

重启容器:docker-compose restart [容器名]

查看容器:docker-compose ps [容器名]

查看日志:docker-compose logs [容器名]

posted @ 2023-06-26 17:54  常疯大虾  阅读(64)  评论(0编辑  收藏  举报