docker-compose can be considered a wrapper around the docker CLI (in fact it is another implementation in python as said in the comments) in order to gain time and avoid 500 characters-long lines (and also start multiple containers at the same time). It uses a file called docker-compose.yml in order to retrieve parameters.

You can find the reference for the docker-compose file format here.

So basically docker-compose build will read your docker-compose.yml, look for all services containing the build: statement and run a docker build for each one.

Each build can specify a Dockerfile, a context and args to pass to docker.

To conclude with an example docker-compose.yml file:

version: '3.2'

services:
  database:
    image: mariadb
    restart: always
    volumes:
      - ./.data/sql:/var/lib/mysql

  web:
    build:
      dockerfile: Dockerfile-alpine
      context: ./web
    ports:
      - 8099:80
    depends_on:
      - database 

When calling docker-compose build, only the web target will need an image to be built. The docker build command would look like:

docker build -t web_myproject -f Dockerfile-alpine ./web
Answer from hugoShaka on Stack Overflow
🌐
Docker
docs.docker.com › reference › docker compose › docker compose build
docker compose build | Docker Docs
If the Compose file specifies an image name, the image is tagged with that name, substituting any variables beforehand. See variable interpolation. If you change a service's Dockerfile or the contents of its build directory, run docker compose build to rebuild it.
🌐
Docker Docs
docs.docker.com › reference › compose file reference › compose build specification
Compose Build Specification | Docker Docs
It tells Compose how to (re)build an application from source and lets you define the build process within a Compose file in a portable way. build can be either specified as a single string defining a context path, or as a detailed build definition.
Discussions

Docker Compose: do I need to run docker compose build first?
Nope, if your compose file has a Dockerfile defined in it and the image doesn't exist it will automatically build before running when you do an up. If you run a build when you have a Dockerfile defined, it will build all buildable images in your compose file and not run them. More on reddit.com
🌐 r/docker
17
8
April 26, 2022
I'm really not understanding `docker-compose build`
I use docker-compose pull and then docker-compose up. I use this with the -f flag to specify a .yml config file which defines the network and ports etc. That works. However it’s incredibly slow, even on the best hardware (Apple Macbook Pro M1 with 64GB RAM). I noticed that the build command ... More on forums.docker.com
🌐 forums.docker.com
1
0
August 9, 2022
Docker-compose build and up
I started with the django-tailwind guide, then added the code from the first tutorial to it. When I run docker-compose build it builds (19/28) of the commands, I assume. When I run docker-compose up I get the error gmo-django-lightsail-tailwind-1 | CommandError: gmo-django-lightsail-tailwind-1 ... More on forums.docker.com
🌐 forums.docker.com
10
0
May 19, 2023
deployment - docker-compose build and up - Stack Overflow
I am not an advance user so please bear with me. I am building a docker image using docker-compose -f mydocker-compose-file.yml ... on my machine. The image then been pushed to a remote docker re... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Docker Docs
docs.docker.com › manuals › docker compose › docker compose quickstart
Docker Compose Quickstart | Docker Docs
For more information on the compose.yaml file, see How Compose works. ... With a single command, you create and start all the services from your configuration file. Compose builds your web image, pulls the Redis image, and starts both containers.
🌐
Docker Docs
docs.docker.com › manuals › docker compose
Docker Compose | Docker Docs
Learn the key concepts of Docker Compose whilst building a simple Python web application.
Find elsewhere
🌐
Development Containers
containers.dev › guide › dockerfile
Using Images, Dockerfiles, and Docker Compose
version: '3.8' services: devcontainer: build: context: . dockerfile: Dockerfile volumes: - ../..:/workspaces:cached network_mode: service:db command: sleep infinity db: image: postgres:latest restart: unless-stopped volumes: - postgres-data:/var/lib/postgresql/data environment: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres POSTGRES_DB: postgres volumes: postgres-data:
🌐
Docker Community
forums.docker.com › general
I'm really not understanding `docker-compose build` - General - Docker Community Forums
August 9, 2022 - I use docker-compose pull and then docker-compose up. I use this with the -f flag to specify a .yml config file which defines the network and ports etc. That works. However it’s incredibly slow, even on the best hardware…
🌐
Docker
docs.docker.com › manuals › docker build › bake › building with bake from a compose file
Building with Bake from a Compose file | Docker Docs
I'm Gordon, your AI assistant for Docker and documentation questions. ... You've reached the maximum of questions per thread. For better answer quality, start a new thread. Start a new thread · Answers are generated based on the documentation. ... Bake supports the Compose file format to parse a Compose file and translate each service to a target. # compose.yaml services: webapp-dev: build: &build-dev dockerfile: Dockerfile.webapp tags: - docker.io/username/webapp:latest cache_from: - docker.io/username/webapp:cache cache_to: - docker.io/username/webapp:cache webapp-release: build: <<: *build-dev x-bake: platforms: - linux/amd64 - linux/arm64 db: image: docker.io/username/db build: dockerfile: Dockerfile.db
🌐
Docker Community
forums.docker.com › general
Docker-compose build and up - General - Docker Community Forums
May 19, 2023 - I am trying to Dockerize a Django app with tailwind to deploy to lightsail. I followed two tutorials. Both work individually. Now I am trying to combine the both. I started with the django-tailwind guide, then added the code from the first tutorial to it. When I run docker-compose build it builds (19/28) of the commands, I assume.
🌐
LabEx
labex.io › tutorials › docker-how-to-use-docker-compose-build-command-to-build-services-555073
How to use docker compose build command to build services | LabEx
Learn how to use the docker compose build command to build services from a Docker Compose file. Explore rebuilding services, using build arguments, and the --no-cache option for efficient Docker builds.
🌐
Sumo Logic
sumologic.com › home › how to build applications with docker compose
How to build applications with docker compose
May 9, 2025 - We’ve added a single line “build: ./helloworld” to the helloworld service. It instructs Docker Compose to enter the compose/helloworld directory, run a docker build there, and tag the resultant image as helloworld:1.0. It’s very concise. You’ll notice that we haven’t added the application app.py into the container.
🌐
CodeSignal
codesignal.com › learn › courses › multi-container-orchestration-with-docker-compose › lessons › building-custom-docker-images-with-compose
Building Custom Docker Images with Compose
With the docker compose build command, you can explicitly build any images specified in the compose file: Executing this command initiates the image build process, with Docker reading the Dockerfile referenced in the Compose file and constructing the image layer by layer.
🌐
Docker
docs.docker.com › manuals › docker compose › build dependent images
Build dependent images | Docker Docs
services: a: build: dockerfile: a.Dockerfile # built image will be tagged <project_name>_a b: build: dockerfile: b.Dockerfile additional_contexts: # `FROM base_image` will be resolved as a dependency on service "a" which has to be built first base_image: "service:a" Using Bake let you pass the complete build definition for all services and to orchestrate build execution in the most efficient way. To enable this feature, run Compose with the COMPOSE_BAKE=true variable set in your environment.
🌐
Medium
vaibhavdjain.medium.com › docker-compose-and-build-command-114e09b25598
Docker compose and build command. docker-compose up and docker-compose… | by Vaibhav Jain | Medium
August 21, 2023 - Instead of building a single Docker image, Docker Compose allows you to define multiple services (containers) and their configurations in a single YAML file (docker-compose.yml). The docker-compose up command reads the docker-compose.yml file and starts the services defined within it.
🌐
TechRepublic
techrepublic.com › home › how to build a docker compose file
How to build a Docker Compose file - TechRepublic
November 3, 2022 - To put it simply: Docker Compose builds a stack of applications to run a complete service. The docker-compose.yml file is broken into sections, each section represents a single container which, when combined with the other containers, create ...
Top answer
1 of 2
1

As of compose 1.24 along with the 18.09 release of docker (you'll need at least that client version on the remote host), you can run docker commands to a remote host over SSH.

# all docker commands in this shell will not talk to the remote host
export DOCKER_HOST=ssh://user@host
# you can verify that with docker info to see which engine you're talking to
docker info
# and now run your docker-compose up command locally to start/stop containers
docker-compose up -d

With previous versions, you could configure TLS certificates to allow specific clients to connect to the docker API over a network connection. See these docs for more details.

Note, if you have host volumes, the variables and paths will be expanded to your laptop directories, but the host mounts will happen on the remote server where those directories may not exist. This is a good situation to switch to named volumes.

2 of 2
1

Everything you can do with Docker Compose, you can do with plain docker commands.

Depending on how exactly you're interacting with the remote server, your tooling might have native ways to do this. One specific example I'm familiar with is the Ansible docker_container module. If you're already using a tool like Ansible, Chef, or Salt, you can probably use a tool like this to do the same thing your docker-compose.yml file does.

But otherwise there's more or less a direct translation between a docker-compose.yml file

version: '3'
services:
  foo:
    image: me/foo:20190510.01
    ports: ['8080:8080']

and a command line

docker run -d --name foo -p 8080:8080 me/foo:20190510.01

My experience has been that the docker run commands quickly become unwieldy and you want to record them in a file; and once they're in a file, you start to wish they were in a more structured format, even if you need an auxiliary tool to run them; which brings you back to copying around the docker-compose.yml file. I think that's pretty routine. (Something needs to tell the server what to run.)

🌐
Docker Community
forums.docker.com › image builds
Docker Build from compose using a Dockerfile from Host? - Image Builds - Docker Community Forums
July 5, 2025 - Hi, i want to build my own Image from a Dockerfile via Docker-compose. The Dockerfile for this is on the Host System in /home/docker/ How to do this ? version: "1.0" name: "test" services: test: container_name: test build: context: /home/docker/test dockerfile: dockerfile network_mode: host environment: - TZ=Europe/Berlin volumes: - /home/docker/test:/home/docker/test logging: driver...
🌐
Docker
docs.docker.com › guides › building compose projects with bake
Building Compose projects with Bake | Docker Docs
For example, to build the vote service with this configuration, run: ... The docker compose build command is useful when you only need to build images without running services.