Docker compose and common commands in Linux

Time:2021-3-9

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 https://raw.githubusercontent.com/topsale/resources/master/docker/docker-compose
  • 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 https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose > /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 https://antoniopeng.com/2019/08/02/docker/Linux%E5%AE%89%E8%A3%85DockerCompose%E5%8F%8A%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E6%B1%87%E6%80%BB/
  • 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!