Docker - Docker Compose use

Foreword

  Use docker can quickly deploy project, regardless of environmental problems, but if the time required to deploy multiple containers, one by one is very cumbersome to deploy, and you can easily use docker compose efficient to deploy a plurality of containers

System: CentOS Linux release 7.6.1810

Installation docker compose

  Refer to the official website command to install  https://docs.docker.com/compose/install/

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

  Check the installation

docker-compose --version

Create a docker-compose documents

  For ease of operation, the docker all files related to a folder in the

  

  Create a docker-compose.yml file in the / root / docker / compose directory, file reads as follows

version: '3'
services:
  mongodb:
     container_name: em.db
     image: docker.io/mongo
     ports:
       - "27017:27017"
     volumes:
       - ../mongo/db:/data/db

  web-em:
    container_name: em.web
    build: ../dotnet/EM/
    depends_on:
      - mongodb

  reverse-proxy:
    container_name: em.proxy
    image: docker.io/nginx
    depends_on:
      - web-em
    ports:
      - "80:80"
    volumes:
      - ../nginx/proxy.conf:/etc/nginx/conf.d

  services in each name is the network name, there is no need link can replace ip address in the configuration file, compose a document in a default boot container network

  As used herein, a relative path, to facilitate a subsequent transplant to other servers

  Parameter Description:

    container_name container name

    Mirror image, if the local does not exist, the default to get docker hub

    ports port mapping

    Mount volumes file

    build with the build command to create the image file according to dockerfile

    depends_on dependence, the container can be used to specify start-up sequence, only after the start dependency, will start

Execution docker compose

cd /root/docker/compose
docker-compose up -d

  First, enter the directory docker-compose.yml file you just created, execute docker-compose command, start to run background

  

  If you follow the code needs to be updated, plus --build command will recreate the mirror and run the container, the container will depend on restart

to sum up

  Then we see the use of docker compose, deploy on a new server, only need to copy the file in the past, the implementation of docker-compose.yml file can be very efficient

    

 

Guess you like

Origin www.cnblogs.com/sinianchangliu/p/11315543.html