Suppose that I type the following command
docker-compose -f docker-compose.yml build --build_args PARAM=1
How should I write my docker-compose.yml such that the yml fiel gets the argument PARAM, whose value is 1? 
My yml file is below.
version: '3.7'
services:
  web:
    build:
      context: .
      dockerfile: ./Dockerfile
      args: 
         - MY_PARAM: ${PARAM}
      ports:
         - "5000:5000"
    image: sample-img:1.0
I added
args: 
   - MY_PARAM: ${PARAM}
below build. Is this correct?
Here is how you can pass build arguments while using compose -
Allow arguments support in Dockerfile.
FROM foo:bar   
ARG PARAM
ARG PARAM2
.................
Now you can pass these arguments in two different ways -
During runtime -
docker-compose -f docker-compose.yml build --build-arg "PARAM=1 PARAM2=2"
Within compose using shell -
$ export PARAM=1 PARAM2=2
Change docker compose as below -
dockerfile: ./Dockerfile.foo
args:
  PARAM: ${PARAM}
  PARAM2: ${PARAM2}
Build it -
$ docker-compose -f docker-compose.yml build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With