build
What is build?
build: Tells Compose to build an image from a Dockerfile instead of pulling one. Can point at a context and a specific Dockerfile. In Docker Compose, the build key tells Compose to build an image from a Dockerfile instead of downloading one. You can set the build context, the Dockerfile name and build arguments.
Frequently asked questions about build
How is build used in practice?
This is typical for your own application, while services like MySQL and Redis use image to pull an official image. docker compose up --build rebuilds before starting, which you need after changing the Dockerfile or dependencies.
What should you keep in mind with build?
Keep the build context small. Compose sends the whole context folder to the builder, so add a .dockerignore that excludes node_modules, vendor, .git and log files. That makes builds faster and stops secrets in local files from ending up in an image. You can combine build and image to give the built image a name and tag.
What does an example of build look like?
services: web: build: context: . dockerfile: Dockerfile args: VERSION: "1.0" At a glance
| Category | Docker |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |