Docker-compose 默认排除服务

标签 docker docker-compose

如果我在 docker-compose 项目中定义了很多服务,如何从默认的 docker-compose up 命令中排除某个服务?

例如,我有一个 nginx 服务和一个 ssl 服务。它们发生冲突,因为它们都消耗端口 80,所以我怎样才能使 ssl 服务不会启动,除非我专门运行该服务,并且默认情况下 up 命令将执行除 ssl 之外的所有操作服务?

最佳答案

docker-compose 1.28.0 开头新service profiles就是为此而生的!使用profiles,您可以将服务标记为仅在特定配置文件中启动,例如:

services:
  webapp:
    # ...

  nginx:
    # ...
    profiles: ["nginx"]
    ports:
      - 80:80

  ssl:
    # ...
    profiles: ["ssl"]
    ports:
      - 80:80
docker-compose up # start only your webapp services
docker-compose --profile nginx up # start the webapp and nginx service
docker-compose --profile ssl up # start the webapp and ssl service
docker-compose run ssl # run the ssl service

根据您的具体用例/设置,将您的服务拆分为 multiple docker-compose.yml files 可能会更好.

关于Docker-compose 默认排除服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50848797/

相关文章:

node.js、Rabbitmq 和 Docker : the service using seneca seems to start before rabbitmq

linux - Linux 容器上的 Kestrel 证书 "no such file"可以在 Windows 容器上找到

azure - 如何以非 root 用户身份在自托管构建代理上执行管道

docker - 在 GCP 启动脚本期间查找用户名

azure - 如何通过 REST API 更新 Azure 应用服务中的容器设置?

java - com.mongodb.MongoSocketOpenException : Exception opening socket 异常

docker - docker-compose构建失败,并带有/bin/sh:apt-get:找不到

mysql - Docker:$'\r':在 Windows 上找不到命令

javascript - Gulp 构建任务在 docker 内失败

docker - 更改 docker-compose 中的卷配置而不丢失数据