Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
How can I run multiple versions of the same build in docker-compose?

TL/DR: Can I use .env file variables in docker-compose's environment directives?


I have a Dockerfile which uses the ARG variable to copy files based on an environment variable.

In my docker-compose I want to run two versions of this container with different configuration.

Is there a way where I can set different filepaths in a single .env file and have it build twice, like the example below?

Or is there a smarter way to accomplish this?


/
/.env
/docker-compose.yml
/app
/app/Dockerfile
/version1/data
/version2/data

/.env


VERSION_1_PATH=./version1/data
VERSION_2_PATH=./version2/data

/app/Dockerfile

FROM node:latest

ARG APP_PATH             # pull this environment variable
COPY $APP_PATH /var/app/ # use it to copy source to the same generic destination

/docker-compose.yml

version: "3"
services:
  version1:
    build: ./app
    container_name: version1
    env_file: 
      - '.env'
    environment:
      APP_PATH: ${VERSION_1_PATH}

  version2:
    build: ./app
    container_name: version2
    env_file: 
      - '.env'
    environment:
      APP_PATH: ${VERSION_2_PATH}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can add args in compose file when to define build, something like follows:

version: '3'
services:
  version1:
    build:
      context: ./app
      args:
        - APP_PATH=${VERSION_1_PATH}

  version2:
    build:
      context: ./app
      args:
        - APP_PATH=${VERSION_2_PATH}

And no need to define .env in env_file if just want it be used in build as .env could default be used in docker-compose.yml. And, environment also not for build, it's for running container.

One example, FYI.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda