Having a base docker-compose.yml
like the following:
version: '2'
services:
web:
build: .
...
How can I extend it to use an image instead?
docker-compose.prod.yml
version: '2'
services:
web:
image: username/repo:tag
Running it with docker docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
still promps:
Building web
Step 1/x : FROM ...
I tried with docker-compose -f docker-compose.yml -f docker-compose.prod.yml up --no-build
:
ERROR: Service 'web' needs to be built, but --no-build was passed.
I'm expecting the "Pulling from name/repo message" instead. Which options do I have? Or do I need to create a complete duplicate file to handle this slight modification?
Define and run multi-container applications with Docker. 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.
To start (up), stop, restart or build a single service (container) using the Docker Compose, simply specify the name of the service against which to run the corresponding docker-compose command.
Description. Builds, (re)creates, starts, and attaches to containers for a service. Unless they are already running, this command also starts any linked services. The docker compose up command aggregates the output of each container (like docker compose logs --follow does).
The key difference between the Dockerfile and docker-compose is that the Dockerfile describes how to build Docker images, while docker-compose is used to run Docker containers.
To use build instead image in docker-compose.override.yml
you should replace image with local image name and then build this image with target.
In docker-compose.override.yml
:
image: username-repo-tag
build:
context: .
target: username-repo-tag
In your Dockerfile
you should add target to FROM
tag:
FROM username/repo:tag as username-repo-tag
...
your instructions
...
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