1

Test Dockerfile

FROM alpine:latest
RUN env
ARG buildno
RUN env

RUN echo "Buildno: ${buildno}"

ENV buildno=${buildno}
RUN echo "Buildno: ${buildno}"

Sample docker-compose.yml

version: "3.9"
services:
  db:
    build:
      context: .
      args:
        buildno: 1

docker compose build does not recognize that I passed an argument

❯ docker compose build --progress=plain --no-cache
#1 [internal] load build definition from Dockerfile
#1 sha256:992c28c35229487c58b557ccebcbb8772478b17e7152af31cc17ff8a2dd5700b
#1 transferring dockerfile: 32B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:3fc1d3b238273b1e933207500d598f0e582aa027e6d4fc4ad6cf4cfffc7cb84c
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/alpine:latest
#3 sha256:d4fb25f5b5c00defc20ce26f2efc4e288de8834ed5aa59dff877b495ba88fda6
#3 DONE 22.3s

#4 [1/5] FROM docker.io/library/alpine:latest@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
#4 sha256:4377fd7ee933f9abee380281596860b3799a6ae79feb340aabca95266dfa3c7a
#4 CACHED

#5 [2/5] RUN env
#5 sha256:be6eea4298c6fb361d86faf696bfc838c149cb5c271dd16ea1a299692826974c
#5 0.268 SHLVL=1
#5 0.268 HOME=/root
#5 0.268 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#5 0.268 PWD=/
#5 DONE 0.3s

#6 [3/5] RUN env
#6 sha256:23b8c1e3fd3690c128e2a55ef62dfaf23b3cfa0a453b0153a5f2e49f2e4e0f60
#6 0.390 SHLVL=1
#6 0.390 HOME=/root
#6 0.390 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#6 0.390 PWD=/
#6 DONE 0.4s

#7 [4/5] RUN echo "Buildno: ${buildno}"
#7 sha256:3c016f4ac1f74bb8c620d650a64430c97db000e68f2e90ba7b57a1fabd8e0429
#7 0.480 Buildno: 
#7 DONE 0.5s

#8 [5/5] RUN echo "Buildno: "
#8 sha256:126fb7196a18d7c37b4bd6d3047bd1f8b85194e8f51236be3e2feeccb1618448
#8 0.501 Buildno: 
#8 DONE 0.5s

#9 exporting to image
#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#9 exporting layers 0.1s done
#9 writing image sha256:ea5a8f5ae5de47d0a24a1677e9b7e53cf260baa118237c94c82eebec4e4a6190 done
#9 naming to docker.io/library/dockercomposetest_db done
#9 DONE 0.1s

If I pass the value via the cli --build-arg though it is picked up, so this appears to be an issue with docker compose?

❯ docker compose build --progress=plain --no-cache --build-arg buildno=2
#1 [internal] load build definition from Dockerfile
#1 sha256:5a5f2608ee72730359e95a730d180af322b44d3bcdb6ea91e8992d017ec248f5
#1 transferring dockerfile: 32B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:abba8545a73f90b4698337406c49e4d0fa6966c6e689ac32f7805a241632ec40
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/alpine:latest
#3 sha256:d4fb25f5b5c00defc20ce26f2efc4e288de8834ed5aa59dff877b495ba88fda6
#3 DONE 10.5s

#4 [1/5] FROM docker.io/library/alpine:latest@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
#4 sha256:4377fd7ee933f9abee380281596860b3799a6ae79feb340aabca95266dfa3c7a
#4 CACHED

#5 [2/5] RUN env
#5 sha256:be6eea4298c6fb361d86faf696bfc838c149cb5c271dd16ea1a299692826974c
#5 0.264 SHLVL=1
#5 0.264 HOME=/root
#5 0.264 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#5 0.264 PWD=/
#5 DONE 0.3s

#6 [3/5] RUN env
#6 sha256:8c552c6113c92a1f6d4e4489d771c4b7ae89884edaa0de36e05aa1f1dc3b91de
#6 0.430 SHLVL=1
#6 0.430 HOME=/root
#6 0.430 buildno=2
#6 0.430 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#6 0.430 PWD=/
#6 DONE 0.5s

#7 [4/5] RUN echo "Buildno: 2"
#7 sha256:143f19962211b5fc0d418112ffb5d7cd6c8e2601dc1ee57012c15ce95ecb6ddc
#7 0.457 Buildno: 2
#7 DONE 0.5s

#8 [5/5] RUN echo "Buildno: 2"
#8 sha256:18d66f93e7671b75c99f6b9811fb2d17995ae9327d9691c12c0d11983cf232d7
#8 0.441 Buildno: 2
#8 DONE 0.5s

#9 exporting to image
#9 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#9 exporting layers 0.1s done
#9 writing image sha256:550109791ad859f682ac8686795400d612354a539afd55a9ad268f603dcce3f0 done
#9 naming to docker.io/library/dockercomposetest_db done
#9 DONE 0.1s

The buildno value shows up as expected after being defined on line 3 and appears in the environment variable as it should. Any thoughts? I get the same results using my windows client as my WSL2 one.

1
  • 1
    docker-compose does work though... Commented May 31, 2021 at 19:17

1 Answer 1

1

This appears to be a known issue with docker compose as opposed to docker-compose

https://github.com/docker/compose/issues/8329

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.