I was looking forward to know, how can i restart a specific service in a docker-compose.yaml file for example
version: '2.1'
volumes:
-grid-shared:
services:
service-A:
build:
context: .
dockerfile: ../../Dockerfile
service-B:
build:
context: .
dockerfile: ../../Dockerfile
service-C:
build:
context: .
dockerfile: ../../Dockerfile
After i run docker-compose up
I mad some changes in service-A Dockerfile file and now i want to sync my changes to only that container
You can use docker-compose restart service-A for restarting containers but am not sure if this will trigger a build.
You might end up using the same cached service.
But what will work for sure is docker-compose down service-A
and then docker-compose up --build service-A
Related
I have two services in my docker-compose.yaml that use the same build context:
service_1:
image: 'service_1:latest'
container_name: service_1
env_file:
- ./service_dir/.env
ports:
- "8000:80"
build:
context: ./service_dir/
dockerfile: Dockerfile
volumes:
- ./service_dir/app:/app
command: /start-reload.sh
service_2:
container_name: service_2
build:
context: ./service_dir/
dockerfile: Dockerfile
command: python app/my_script.py
Building this takes forever. I assume it has something to do with the fact that the build context is taken twice to the docker daemon? I'm not sure if these commands could be run in the same service but I'd prefer to have two separate containers so I can e.g. follow service_2 logs more easily. Any suggestions for a good solution to my problem?
I've seen the following in https://www.distributedpython.com/2018/11/15/celery-docker/
Which reuses the built image I believe
services:
worker:
build: .
image: &img worker
beat:
build: .
image: *img
Since I'm using Dockerfile, I can do something like this, I see it's rebuilding the image (pip install in Dockerfile runs twice for each service)
services:
worker:
build:
context: ../../
dockerfile: ./retention/docker/celery/Dockerfile
image: &img worker
container_name: celery
# command: [celery, worker, --app=app1, --loglevel=INFO]
beat:
build:
context: ../../
dockerfile: ./retention/docker/celery/Dockerfile
image: *img
# command: [celery, beat, --app=app1, --loglevel=INFO]
How can I build just one image and reuse it?
you need to use the same :
image: myimage:mytag
for the both services
then docker-compose build will use cache
You can re-use the same image in the same docker-compose but the order will mater, what if the image is not built yet and service B starting with that image that not exist yet which is supposed to be built in service A stage?
So add depends_on will help this race case also remove the build context from the beat service.
version: '3.7'
services:
worker:
image: worker_beat
build:
context: ../../
dockerfile: ./retention/docker/celery/Dockerfile
container_name: celery
command: [celery, beat, --app=app1, --loglevel=INFO
beat:
image: worker_beat
depends_on:
- worker
command: [celery, beat, --app=app1, --loglevel=INFO]
to run your stack you will just need docker-compose up --build
https://docs.docker.com/compose/production/
Removing any volume bindings for application code, so that code stays
inside the container and can’t be changed from outside
I'd like to build image for production with my app code.
I have a file docker-compose-prod.yml
version: '3'
services:
------
nginx:
build:
context: ./docker/nginx
image: my_nginx:v1
ports:
- 80:80
volumes:
- ./docker/app:/var/www/html
depends_on:
- php
------
The code of my app located in ./docker/app.
The Dockerfile located in ./docker/nginx and I can't with command COPY to copy an app code outside /docker/nginx folder.
When I run a build command I get an image without app contend in /var/www/html:
docker-compose -f docker-compose-prod.yml build
How to build an image in this case with my an app code?
You could pass the dockerfile in the build argument: https://docs.docker.com/compose/compose-file/#dockerfile
This way, I think that you can change your app context to be ./docker, and in the Dockerfile, copy the app folder to /var/www/html. This way, you no longer have to specify a volume when starting the app.
Correct config looks like:
version: '3'
services:
------
nginx:
build:
context: ./docker
dockerfile: nginx/Dockerfile-prod
image: my_nginx:v1
ports:
- 80:80
------
And the Dockerfile-prod in /docker/nginx
...
COPY ./app /var/www/html
...
I tried to run nginx like following:
docker-compose.yml
version: '3'
services:
web:
image: nginx
ports:
- "3011:80"
After I run docker-compose up, I found that nginx working success at 127.0.0.1:3011
But if I copy the nginx's dockerfile at dockerHub:
And change the docker-compose.yml like following:
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "3011:80"
Then nginx won't working at 127.0.0.1:3011.
Why is that?
If you changed you Dockerfile, you should run
docker-compose up --build -d
to build your docker image before docker-compose runs it up.
tested this using the dockerfile linked above and the compose for it, this worked perfectly fine on my side. Perhaps you need to run docker-compose build and then docker-compose up --force-recreate it may be that you are using a stale container that may be broken.
Trying to use docker-compose for the first time, but not having much luck. I have the following setup:
docker-compose version 1.8.0, build f3628c7
/home/GabeThermComposer contains the docker-compose.yml
/home/GabeThermComposer/GabeThermApache contains Dockerfile
/home/GabeThermComposer/GabeThermPHPMyAdmin contains Dockerfile
/home/GabeThermComposer/GabeThermDB contains Dockerfile and nest-init.sql
When I create docker images using the Dockerfile in each subdir, it all works without issues. I was hoping with the docker-compose.yml to do all the seperate building of images at once.
The docker-compose.yml looks like this:
version: '2'
services:
GabeThermDB:
build:
context: ./GabeThermDB
dockerfile: Dockerfile
GabeThermApache:
build:
context: ./GabeThermApache
dockerfile: Dockerfile
ports:
- "80:80"
GabeThermPHPMyAdmin:
build:
context: ./GabeThermPHPMyAdmin
dockerfile: Dockerfile
ports:
- "8080:80"
When trying to run "docker-compose up", I get the following error:
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.GabeThermPHPMyAdmin.build contains unsupported option: 'ports'
services.GabeThermApache.build contains unsupported option: 'ports'
I have no clue on what is wrong with this. I think I did exactly as other examples have shown. Btw, I do know that the "context:" and "dockerfile:" is overdone, but since I'm new, I wanted to be sure to what files I'm pointing in case I forget it automatically dives into the subdir and runs the Dockerfile.
Any help is appreciated.
You have to move the ports out of the build block.
version: '2'
services:
GabeThermDB:
build:
context: ./GabeThermDB
dockerfile: Dockerfile
GabeThermApache:
build:
context: ./GabeThermApache
dockerfile: Dockerfile
ports:
- "80:80"
GabeThermPHPMyAdmin:
build:
context: ./GabeThermPHPMyAdmin
dockerfile: Dockerfile
ports:
- "8080:80"