Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

540
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!