I have the following docker-compose file
version: '3'
services:
node1:
build: node1
image: node1
container_name: node1
node2:
build: node2
image: node2
container_name: node2
I can build both images and start them with a single command
docker-compose up -d --build
But I would like to use build-args on the builds. The original build script of the image outside of the scope of compose looks something like this
#!/bin/sh
docker build \
--build-arg ADMIN_USERNNAME_1=weblogic \
--build-arg ADMIN_PASSWORD_1=weblogic1 \
--build-arg ADMIN_NAME_1=admin \
--build-arg ...
--build-arg ... \
-t test/foo .
Both images would use build-args of the same name but different value. Also, as there are dozens of build args, it would be convenient to store them in a compose service specific build-properties file. Is this possible with docker-compose?
You can specify the arguments directly in your docker-compose file:
node1:
build: node1
args:
ADMIN_USERNNAME: weblogic1
ADMIN_PASSWORD: weblogic1
ADMIN_NAME: admin1
image: node1
container_name: node1
See the official docs for details.