I have a simple Issue with Docker-compose, But Its a random issue.
I have a docker-compose.YAML for spring services, When I update the service and want to check the update, I build a new image to docker daemon with google jib, and I use docker-compose up --force-recreate to get the new updates.
The issue is, most of the time with --force-recreate I will have an error ERROR: for serviceName b'i/o timeout'
So I docker-compose down Then docker-compose up --build which will have the same effect
as docker-compose up --force-recreate according to my simple understanding of docker, but when I do this down up, I have no issue, Any idea what might be the issue for this case?
Related
We were trying to build and run docker-compose project on remote host. I tried using:
docker-compose -H 'ssh://remote_address' up --build
And got
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
So we tried:
docker-compose -H 'ssh://remote_address' build
docker-compose -H 'ssh://remote_address' up
Which worked fine. My problem is I can't find evidence in docs for this to be correct behaviour. Is this a bug in docker-compose, a feature, or a bug in my environment?
I'm not sure of the error you got for the first command, I mean docker-compose -H 'ssh://ip' up --build as it may be really a but, but the three mentioned commands have surely differences. I'll try to explain in my simple way:
First command is docker-compose up --build.
This command finds docker-compose file and rebuilds the image then make it running. Suppose you have made some changes into your docker-compose file, so when you only run docker-compose, you'll get a warning that image is not rebuilt, you should run docker-compose up --build to rebuild it and make everything be built again (despite something done before and present in cache).
Second command is docker-compose build.
This command only builds your image based on docker-compose, but does not run it. You can see the built image by docker image ls or docker images. Also executing docker ps -a should not see your recent built image running.
Third and the last command is docker-compose up.
If this command is entered for the first time, it tries to run everything in Dockerfile if exists and download base image, etc. Then makes the image and runs the container.
If the image has been built before, it just runs it.
Unlike the first command, the third one only runs the latest build of that image, but would not build it again.
In .yml file I have defined: restart: always. Is it possible to create this restart as the equivalent of --force-recreate flag?
I have an issue with XVFB and standard restart doesn't solve an issue but restarts with the flag --force-recreate help and I'm looking for an opportunity to do it automatically.
Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in restart policy details) Source Link:
No --force-recreate is not the equivalent to restart: always
"--force-recreate Recreate containers even if their configuration and image haven't changed."
I use a Makefile for start/stop is also more practical.
Example:
SHELL := /bin/bash
# Docker: up
up:
docker-compose up -d --force-recreate --build
# Docker: down
down:
docker-compose down
... and so on
And than i can use like "make up, make down, make logs, make attach ..."
By the way, in most projects I also use for Automatic Restart and better logging Supervisor
docker-compose fails with a timeout:
docker-compose stop mycontainer
but docker succeeds:
docker stop mycontainer
My questions
What is the difference between docker-compose stop and docker stop?
Where can I get more detailed information about that problem? (I killed docker-compose after a few minutes)
How can I solve that problem with docker-compose?
docker-compose stop it stops running containers that are started when you run command docker-compose start . it base on docker-compose file.
Please take a look content of docker-compose file for more details.
Running docker ps to see what are containers running.
docker stop actually, docker stop running_container_id it stops running container.
Doc says that docker stop sends a SIGTERMand then a SIGKILL to the running container, while docker-compose stop does not mention that. Maybe that is the reason.
Docs:
Compose: https://docs.docker.com/compose/reference/stop/
Docker: https://docs.docker.com/engine/reference/commandline/stop/
You might want to check if you can reproduce that signalling with docker-compose.
Edit: More on signal-handling in Docker Compose: https://docs.docker.com/compose/faq/
Finally I solved that problem by restarting the host vm.
Apparently the docker daemon was in trouble.
Nevertheless I still wonder, why docker-compose stop did not work.
I didn't manage to find out how to use the scale parameter (which allow to run multiple instance of the docker container) without launching the dependencies in the docker-compose file.
Assuming "Worker" depends of "App"
When I do docker-compose up --no-deps --scale worker=2, App will be launched too...
Thanks for helping.
The workaround is :
docker-compose up --no-start worker
docker-compose scale worker=2
docker-composer logs -f worker
This provide the expected behavior.
I'm wondering what is the difference between those two commands?
When I'm doing docker-compose up --build I got a message:
php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs).
I red that it's because it runs as a foreground process and I need to use -d instead.
After running docker-compuse up -d I don't get that message.
And the main question is the result are different between those two commands?
From the docs
docker-compose up builds, (re)creates, starts, and attaches to containers for a service.
docker-compose up -d starts the containers in the background and leaves them running. (this means that if you want to see the logs of the containers you will have to use docker-compose logs -f)
docker-compose up --build builds images before starting containers
This similar question: docker-compose up vs docker-compose up --build vs docker-compose build --no-cache
mentions that:
if you add the --build option, it is forced to build the images even when not needed.