1. 程式人生 > >docker-compose編排

docker-compose編排

建立並啟動容器
docker-compose up -d
 
備註:
-d  後臺啟動並執行容器

前提是你在執行該命令的時候已經編寫好了docker-compose.yml檔案,在這個檔案的當前目錄執行上述命令
  centos7安裝docker-compose
下載安裝
curl -L https://github.com/docker/compose/releases/download/1.11.1/docker-compose-`uname -s`-`uname -m` > /usr/bin/docker-compose

授權 chmod +x /usr/bin/docker-compose

檢視安裝情況 [
[email protected]
~]# docker-compose -
version
docker-compose version 1.11.1, build 7c5d5e4
  例項(將下列程式碼另存為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