头图

Docker Compose is an official open source project of Docker, responsible for the rapid orchestration of Docker container clusters. By using a docker-compose.yml template file to define one or more containers to meet a software application operating environment.
Docker Compose has three usage scenarios

  • Dockerfile file to build the container, customize the image
  • docker-compose.yml build software environment
  • docker-compose starts the container

installation

In window and mac, only installing docker will bundle Docker Compose to install
Linux users use the following command to install

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

Executable permissions on binary files

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

Check if the installation is successful

$ docker-compose version
docker-compose version 1.29.1, build c34c88b2
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

Write docker-compose.yml

version: "3.9"

# 服务 在它下面可以定义应用需要的一些服务,每个服务都有自己的名字、使用的镜像、挂载的数据卷、所属的网络、依赖哪些其他服务等等。
services:
  #服务名称
  webapp:
    # docker 运行在名字,在docker ps -a 看到的名字
    container_name: mynginx
    # 镜像 : 标签
    image: nginx:syf
    # 端口映射 主机端口: 容器端口
    ports:
      - "80:80"
    # 物理卷挂载 将本地路径挂载到容器内
    volumes:
      - D:/docker-compose/html:/usr/share/nginx/html
    dns:
      - 192.168.123.1

Compose has multiple versions that support 2.x and 3.x, the version provided below corresponds to the docker version

Compose file formatDocker Engine release
Compose specification19.03.0+
3.819.03.0
3.718.06.0+
3.618.02.0+
3.517.12.0+
3.417.09.0+
3.317.06.0+
3.217.04.0+
3.11.13.1+
3.01.13.0+
2.417.12.0+
2.317.06.0+
2.21.13.0+
2.11.12.0+
2.01.10.0+

Many configurations can be added to the docker-compose.yml file. If you are interested, see 160d7410521fc0 official website document

docker-compose command

docker-compose [-f <arg>...] [--profile <name>...] [options] [--] [COMMAND] [ARGS...]

Start the container

docker-compose -f docker-compose.yml up -d

docker-compose often uses commands

  • build build or refactor service
  • create Create service
  • down stop and delete container resources
  • exec executes the command type docker exec command in the container
  • logs View container logs, similar to docker logs
  • restart restart the container
  • start Start the service
  • up creates and starts the container

神易风
106 声望52 粉丝

alert("hello world")


« 上一篇
docker安装MySQL
下一篇 »
MySQL主从复制