preface

The previous article uses docker to build nginx service, start nginx container is using shell command, very inconvenient. It’s easy to forget commands when the container is deleted. Next, I used dokCer-compose container choreography to manage the Nginx service.

Introduction to the

Docker Compose is a Docker tool for defining and running complex applications. An application that uses Docker containers usually consists of multiple containers. Docker Compose no longer requires a shell script to start the container. Compose manages multiple Docker containers through a single configuration file, in which all containers are defined by services, and then uses the Docker-compose script to start, stop, and restart the application, as well as the services in the application and all containers that depend on the service. This is ideal for scenarios where multiple containers are used in combination for development.

The installation image

Download the docker - compose binaries are installed curl - https://github.com/docker/compose/releases/download/1.23.2/run.sh > / usr/Llocal/bin/docker-compose adds the executable permission chmod +x /usr/local/bin/docker-compose // Check docker-compose versionCopy the code

Create the docker-comemage. yml file


services:
  nginx:
    container_name: nginx 
    image: nginx
    restart: always
    ports:
      - 80:80
    volumes:
      - /home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf
      - /home/www:/home/www
      - /home/docker-nginx/log:/var/log/nginx
      - /home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
      - /home/docker-nginx/html:/usr/share/nginx/html
      
      
Copy the code

Container_name: container name Image: mirror ports: port volumes: path mapping

Start the

  1. Upload docker-comemage. yml to the /home/docker folder
  2. Go to the /home/docker folder
cd /home/docker
Copy the code
  1. Start the docker – compose
docker-compose up -d nginx 
Copy the code

Docker-compose common command


docker-compose execDocker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose Docker-compose run --no-deps --rm php-fpm PHP -v docker-compose run --no-deps --rm php-fpm PHP -v docker-compose run --no-deps --rm php-fpm Docker-compose build nginx, docker-compose, docker-compose, docker-compose, docker-compose, docker-compose, docker-compose Docker-compose build --no-cache Nginx build without cache. Docker-compose logs -f nginx - Docker-compose logs -f nginx - docker-compose config-q Verify (docker-comemess. yml) file configuration, if the configuration is correct, no output, when the file configuration is wrong, output error message. Docker-compose events --json Nginx outputs nginx docker-compose logs in JSON format. Docker-compose pause nginx docker-compose unpause Nginx restore ningx containers docker - compose rm nginx delete (delete) must be closed before the container docker - compose stop nginx stop nignx container docker - compose start nginx Start the Nignx containerCopy the code

At the end

This is a simple implementation of using Docker-compose to orchestrate containers. In real production applications, multiple containers will be started at once. But this is not simple enough, I want to use the mouse point and point to achieve container management, finally I found portainer, next time I will use Portainer to achieve visual management of Docker.