Docker compose and common commands in Linux


Introduction to docker compose

Docker compose is one of the official choreography projects of docker, which is responsible for the rapid choreography of docker container cluster

The positioning of compose: defining and running applications with multiple dockers and containers

In daily work, we often encounter the situation that multiple containers cooperate with each other to complete a task. For example, to implement a web project, in addition to the web service container itself, we often need to add back-end database, load balancing service container and other service containers. andDocker ComposeJust to meet this requirement, it allows users to use a singledocker-compose.ymlTemplate file to define a set of associated containers as a project

There are two important concepts in compose

  • Service: an application actually includes several running container instances
  • Project: a complete business unit composed of a set of associated application containers

Install docker compose

Binary package installation

  • Move to installation directory

    $ cd /usr/local/bin
  • Download the corresponding binary package

    $ wget
  • Grant operation permission

    $ sudo chmod +x /usr/local/bin/docker-compose

PIP installation

  • If the computer architecture is arm (for example: strawberry pie), it should be downloaded from the PIP source

    $ sudo pip install -U docker-compose

    See the following output information, indicating that the installation is successful

    Collecting docker-compose
      Downloading docker-compose-1.17.1.tar.gz (149kB): 149kB downloaded
    Successfully installed docker-compose cached-property requests texttable websocket-client docker-py dockerpty six enum34 backports.ssl-match-hostname ipaddress

Download the bash completion Command Patch

Patch download command

$ curl -L > /etc/bash_completion.d/docker-compose

Uninstall docker compose

Uninstall on Linux

$ sudo rm /usr/local/bin/docker-compose

Unloading on ARM

$ sudo pip uninstall docker-compose

Common commands of docker compose

  • Foreground running container

    $ docker-compose up
  • Background run container

    $ docker-compose up -d
  • Start container

    $ docker-compose start
  • Stop container

    $ docker-compose stop
  • Stop and remove container

    $ docker-compose down
  • Author: Peng Chao
  • This article first appeared in personal blog
  • Copyright notice: except for special notice, all articles in this blog adopt CC by-nc-sa 4.0 license agreement. Reprint please indicate from Peng Chao | blog!