Using Docker Compose to build image before running
What I learned today — 27 July 2018
1 min readJul 27, 2018
This was one of those blind moments, but today I realised that a docker-compose.yml
file can also be used for building an image if the image is not yet available.
To make Docker Compose build a missing image simply add the build
attribute. The simplest version is build: .
which will use the current directory as the docker context and build the image using the Dockerfile
found there.
Example
This docker-compose.yml
will build and run an image called “business-banking” which is based on jboss/wildfly.
version: '3'
services:
business-banking:
build: .
image: business-banking
ports:
- "8080:8080"
- "9990:9990"
command: /opt/jboss/wildfly/bin/standalone.sh -bmanagement=0.0.0.0 -b 0.0.0.0