Please help me understand the difference between 'image' and 'build' within docker compose
The three primary differences between the Dockerfile and docker-compose are: The Dockerfile is used to build images while the docker-compose. yaml file is used to run images. The Dockerfile uses the docker build command, while the docker-compose.
docker-compose build : This command builds images in the docker-compose. yml file. The job of the build command is to get the images ready to create containers, so if a service is using the prebuilt image, it will skip this service.
Description. The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context ...
A build is the process of transforming input parameters into a resulting object. Most often, the process is used to transform input parameters or source code into a runnable image. A BuildConfig object is the definition of the entire build process.
image
means docker compose
will run a container based on that imagedocker compose
will first build an image based on the Dockerfile found in the path associated with build (and then run a container based on that image).PR 2458 was eventually merged to allow both (and use image
as the image name when building, if it exists).
therobyouknow
mentions in the comments:
dockerfile:
as a sub-statement beneathbuild:
can be used to specify the filename/path of the Dockerfile.
version: '3' services: webapp: build: context: ./dir dockerfile: Dockerfile-alternate args: buildno: 1
build: expects dockerfile path as an argument, it will build an image first and then use the image to create a container.
image: expects existing image name as argument , it will launch container using this image.
Example:docker-compose.yaml
version: '3' services: service1: build: . ports: - "5000:5000" service2: image: "redis:alpine"
service1 will build an image first based on Dockerfile of current path and run container based on this image.
service2 will download "redis:alpine" image from docker hub and run container on downloaded image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With