Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

211
Vistas
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.

8 months ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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.

8 months ago · Santiago Trujillo Denunciar

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

8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos