Build an Image With Docker Compose

When deploying applications with Docker compose, we can optimise the process and build the images used in the application simultaneously.

Build

Docker Compose allows us to build images during the deployment of applications. This option combines all the application operations under a single configuration file.

Docker Compose uses the build statement to build an image from a dockerfile, as you will see soon. The requirement to build an image with composing is that the Dockerfile needs to be in the same locations as the docker-compose.yml file, and we need to use the build statement.

Below you can see how my application is organised. The Dockerfile and the docker-compose.yml are in the same spot.

You can see the docker-compose.yml file. The build statement uses the dot option to find the Dockerfile, build the image and use it. With the above in place, our compose file doesn’t need to point to any image.

services:
  app:
    build: .
    ports:
      - "5000:5000"

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.