Building and pushing an application
We can also use the docker-compose build
command to just build the images of an application defined in the underlying compose
file. But to make this work, we'll have to add the build information to the docker-compose
file. In the folder, we have a file, docker-compose.dev.yml
, which has those instructions already added:
version: "3.5" services: web: build: web image: fundamentalsofdocker/ch08-web:1.0 ports: - 3000:3000 db: build: database image: fundamentalsofdocker/ch08-db:1.0 volumes: - pets-data:/var/lib/postgresql/data volumes: pets-data:
Please note the build
key for each service. The value of that key indicates the context or folder where Docker is expecting to find the Dockerfile to build the corresponding image.
Let's use that file now:
$ docker-compose -f docker-compose.dev.yml build
The -f
parameter will tell the Docker Compose application which compose file to use.
To push all images to Docker Hub, we can...