Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

395
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda