创建并启动容器
docker-compose up -d 备注:
-d 后台启动并运行容器 前提是你在执行该命令的时候已经编写好了docker-compose.yml文件,在这个文件的当前目录执行上述命令
centos7安装docker-compose
下载安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
授权
chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
查看安装情况
[root@dmpdev ~]# docker-compose -version
docker-compose version 1.24.0, build 0aa59064
实例(将下列代码另存为docker-compose.yml文件,下面设计到nginx、tomcat、redis、activemq镜像,请使用阿里云或者其他国内镜像加速后执行,防止下载慢或者下不下来的情况)
version: '2'
services:
nginx:
image: nginx:1.10.1
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
- /data/nginx/html:/etc/nginx/html
- /data/nginx/nginx.conf:/etc/nginx/nginx.conf
- /data/nginx/log:/var/log/nginx
redis:
image: redis:3.2.8
container_name: redis
ports:
- "6379:6379"
volumes:
- /data/redis/data:/data
- /data/redis/redis.conf:/etc/redis.conf
command: redis-server /etc/redis.conf --appendonly yes
activemq:
image: activemq:5.14.1
container_name: activemq
ports:
- "8161:8161"
tomcat1:
image: tomcat:9.0.0.M20
container_name: tomcat1
ports:
- "8080:8080"
volumes:
- /data/tomcat1/ROOT:/tomcat/webapps/ROOT
- /data/tomcat1/logs:/tomcat/logs
depends_on:
- redis
- activemq
links:
- redis:redis-host
- activemq:activemq-host
tomcat2:
image: tomcat:9.0.0.M20
container_name: tomcat2
ports:
- "8081:8080"
volumes:
- /data/tomcat2/ROOT:/tomcat/webapps/ROOT
- /data/tomcat2/logs:/tomcat/logs
depends_on:
- redis
- activemq
links:
- redis:redis-host
- activemq:activemq-host