Docker Compose

Docker Compose (v2)

在一个yaml文件中定义多个服务,同时启动多个容器。

compose.yaml

  • name
  • services
  • volumes
  • secret
  • config

docker compose command

# 启动服务
docker compose up
# 在后台启动
docker compose up -d
# 停止服务
docker compose stop
# 停止服务并销毁容器
docker compose down
# 停止服务并销毁一切,包括容器和持久卷
docker compose down --volumes

# The docker compose run command allows you to run one-off commands for your services. 
# For example, to see what environment variables are available to the web service
docker compose run web env

# 指定配置文件
docker compose -f production.yml up

Environment variables

The order of precedence (highest to lowest) is as follows:

  1. Set using [docker compose run -e in the CLI](https://docs.docker.com/compose/environment-variables/set-environment-variables/#set-environment-variables-with-docker-compose-run—env)
  2. Substituted from your shell
  3. Set using just the [environment attribute in the Compose file](https://docs.docker.com/compose/environment-variables/set-environment-variables/#use-the-environment-attribute)
  4. Use of the [-env-file argument](https://docs.docker.com/compose/environment-variables/set-environment-variables/#substitute-with—env-file) in the CLI
  5. Use of the [env_file attribute](https://docs.docker.com/compose/environment-variables/set-environment-variables/#use-the-env_file-attribute) in the Compose file
  6. Set using an [.env file](https://docs.docker.com/compose/environment-variables/set-environment-variables/#substitute-with-an-env-file) placed at base of your project directory
  7. Set in a container image in the ENV directive. Having any ARG or ENV setting in a Dockerfile evaluates only if there is no Docker Compose entry for environment, env_file or run --env.

Profiles

If unassigned, the service is always started but if assigned, it is only started if the profile is activated.

类似SpringBoot的application.yaml中的profile

相关推荐

  1. DockerCompose

    2024-03-27 00:34:03       62 阅读
  2. DockerCompose安装mysql及配置

    2024-03-27 00:34:03       60 阅读
  3. Centos7安装Docker和DockerCompose

    2024-03-27 00:34:03       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 00:34:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 00:34:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 00:34:03       82 阅读
  4. Python语言-面向对象

    2024-03-27 00:34:03       91 阅读

热门阅读

  1. 机器学习代码

    2024-03-27 00:34:03       30 阅读
  2. Codeforces Round 936 (Div. 2)

    2024-03-27 00:34:03       31 阅读
  3. 甲方信息安全建设经验

    2024-03-27 00:34:03       34 阅读
  4. python蓝桥杯自行车停放

    2024-03-27 00:34:03       35 阅读
  5. 计算机系统基础 练习题 2

    2024-03-27 00:34:03       32 阅读