I have two Docker Compose files, docker-compose.yml
looks like this
version: '2'
services:
mongo:
image: mongo:3.2
restart: always
volumes:
- /mnt/data/mongodb/data/db:/data/db
redis:
image: redis:3
restart: always
application:
build: .
image: localregistry:5000/mz_application:latest
ports:
- "3000:3000"
links:
- mongo:mongo
- redis:redis
restart: always
and another file used when I do deployment docker-deploy.yml
version: '2'
services:
application:
image: localregistry5000/mz_application:latest
links:
- mongo:mongo
- redis:redis
restart: always
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes_from:
- application
restart: always
links:
- application:application
command: /bin/bash -c "nginx -g 'daemon off;'"
tty: false
So the idea behind using those files is as follows. When I run
docker-compose build
it builds and pushes an image to our local docker registry.
docker-compose -f docker-compose.yml -f docker-deploy.yml build &&
docker-compose -f docker-compose.yml -f docker-deploy.yml up -d
To deploy and run application
pulled from the local registry rather than being rebuilt.
Unfortunately it rebuilds it because when I override application
, build
is still present as it is taken from docker-compose.yml
file.
How to I remove it ? Is there a way to do this - building and pushing and image using one docker-compose file and then only pull using docker compose file override ?
The docker-compose. override. yml is the configuration file where you can override existing settings from docker-compose. yml or even add completely new services. By default, this file does not exist and you must create it.
Docker-compose command doesn't override Dockerfile CMD.
All About Docker Compose Override Entrypoint Entrypoint helps use set the command and parameters that executes first when a container is run. In fact, the command line arguments in the following command become a part of the entrypoint command, thereby overriding all elements mentioned via CMD.
Stops containers and removes containers, networks, volumes, and images created by up .
First of all, if you let me, I found several things to consider. I don't know why do you want to have the same two build destination images but anyway I'll try to answer solutions better than ask why do you try to do that.
Furthermore, note that in your docker-deploy.yml file, for application service, you're not defining build section, so,
docker-compose -f docker-deploy.yml build
will build image with defaultDockerfile
and path:.
services:
application:
build: .
image: localregistry:5000/mz_application:latest
ports:
- "3000:3000"
links:
- mongo:mongo
- redis:redis
restart: always
container_name: app_compose
services:
application:
image: localregistry:5000/mz_application:latest
links:
- mongo:mongo
- redis:redis
restart: always
container_name: app_deploy
build: .
is the same that don't put anything.
When you use docker-compose build
command, it ignores ports:
section. When you use docker-compose up
command, it ignores build:
section.Definitively, if you want to get up a concrete service without rebuilding avoiding image rewriting, you can also do:
docker-compose -f docker-compose.yml build
docker-compose -f docker-deploy.yml run -d nginx /bin/bash -c "nginx -g 'daemon off;'"
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