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

541
Visualizações
docker-compose is not setting container_name from environment variable

I am working on a docker-compose file, in which I need to specify container_name from an environment variable.

My docker-compose.yml file looks like this:

version: '3.0'
services:
  jenkins:
  environment:
    - INSTANCE_NAME=team_1
  image: my_image
  container_name: container_$INSTANCE_NAME
  ports:
    - "80:80"
  expose:
    - "80"

So, I think, when I run docker-compose up it should create container as name, container_team_1, but instead of that it runs as contaner_

I also tried this thing using .env file, but still, I can not use environment variable in container_name,

although, if I run docker-compose config I can see all variables set like follow,

container_name: container_
environment:
  COMPANY_NAME: team_1

but, Actually it is not attaching in container-name.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As I can see in variable substitution section of the docker-compose documentation, you will need to set your $INSTANCE_NAME in the shell that is running the docker-compose up, because:

Compose uses the variable values from the shell environment in which docker-compose is run.

First of all, do something like:

export INSTANCE_NAME=my_instance`

and then:

docker-compose up

Best regards.

about 4 years ago · Santiago Trujillo Relatório

0

You cannot use environment variables defined in docker-compose.yml to variable substitution.

Docker Compose uses .env by default so it should work when you define in .env file

INSTANCE_NAME=team_1

And then run docker-compose up

about 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