Pass the variable to the Docker file from the docker-compose.yml file

I have several docker-compose.yml files with which I want to use the same Dockerfile, with a little change. So I want to pass an argument to this Dockerfile so that I can do something a little different depending on what variable value is set.

What have i tried so far

file docker-compose-A.yml

version: '2' services: django: build: context: . dockerfile: ./docker/Dockerfile args: - SOMETHING=foo 

file docker-compose-B.yml

 version: '2' services: django: build: context: . dockerfile: ./docker/Dockerfile args: - SOMETHING=bar 

I have a docker file in which I want to use something. for instance

 # Dockerfile RUN echo $SOMETHING 

This does not work. SOMETHING is not transferred to the Docker file.

Am I doing it wrong or is this not intended use?

Is there any other way to pass the variable to the Dockerfile from the docker-compose.yml file?

+18
source share
1 answer

I basically skipped the arg declaration in the Docker file.

 # docker-compose.yml file version: '2' services: django: build: context: . dockerfile: ./docker/Dockerfile args: - SOMETHING=foo 

 # Dockerfile ARG SOMETHING RUN echo $SOMETHING 


Shoutout @Lauri for showing me the light.

+33
source

Source: https://habr.com/ru/post/1247502/


All Articles