I'm trying to use parametrize my dockerfiles on build phase and use arguments in Docker-compose. For example in Docker compose I have defined one service called bpp as following:
bpp:
build:
context: .
dockerfile: Dockerfile.bpp
args:
gp : 8080
image: serv/bpp
restart: always
depends_on:
- data
links:
- data
I'm trying to pass argument named gp to Dockerfile.bpp, where I'm using argument when starting a Python application, exposing a port etc. For example in dockerfile.bpp in trying to expose port gp as following:
EXPOSE gp
However, when building docker file by command docker-compose build I get following error: ERROR: Service 'bpp' failed to build: Invalid containerPort: gp
It seems that argument gp is not visible in dockerfile. Any suggestions?
You need to add
ARG gp
to your Dockerfile.https://docs.docker.com/engine/reference/builder/#arg
Worth mentioning that this isn't going to expose the port when you're running it via compose though, you would need to add a
ports
instruction to your docker-compose.yml for that.First, the syntax is:
So try with
gp: 8080
, notgp : 8080
.Second, make sure you are using version 2 of the docker-compose.yml format.
Third, try