📜  docker compose build (1)

📅  最后修改于: 2023-12-03 14:40:48.946000             🧑  作者: Mango

#docker compose build

docker-compose build is a command used to build a Docker container image from a Docker Compose file. This command is used when changes are made to the Dockerfile or any configuration files for a service defined in the Docker Compose file.

##Syntax

docker-compose build [options] [SERVICE…]

##Options

  • --force-rm: Always remove intermediate containers
  • --no-cache: Do not use cache when building the image
  • --pull: Always attempt to pull a newer version of the image
  • --parallel: Build images in parallel
  • -t, --tag: Name and optionally a tag in the 'name:tag' format
  • -q, --quiet: Don't print anything to the console

##Example

An example docker-compose.yml file:

version: "3"
services:
  web:
    build: .
    ports:
      - "5000:5000"

To build the web service defined in the docker-compose.yml file, run the following command:

docker-compose build web

This command will read the Dockerfile and configuration files for the web service, then create a Docker container image called web using those files.

##Conclusion

docker-compose build is a very useful command in the Docker Compose toolchain. It allows developers to easily build Docker container images from Dockerfiles and configuration files defined in a Docker Compose file. By understanding how to use this command and the available options, developers can streamline their development process and build more efficient and reliable Docker images.