docker-compose up dumps several days' worth of logs to stdout - docker

I have an EC2 instance running a dockerized application using docker-compose.
Every time I run docker-compose up, many days' worth of logs to stdout for all services. This means that I have to wait up to an hour before all the logs have been printed and I start seeing recent logs.
Any ideas?

Your problem is that the old containers created by docker-compose are re-used.
Starting with docker-compose up --force-recreate should do the trick.
Though I remember this from the past, and for me, this problem no longer happens. So it could also be something else.
Please make sure the following:
You are using a modern version of docker-compose (I am running 1.29, run docker-compose version)
Please make sure the containers you are starting to are not already running (docker-compose ps), as then you will attach to them instead of starting them and then printing all the logs in the container is common.

Related

i/o timeout when building docker

my docker has began to give me error almost every time I try to rebuild this week.
Sometimes it works, sometimes gives me error.
It always the same message, i/o timeout.
I dont understand, the docker compose yml is correct I assume, since it has been working fine before.
I have tried to remove all containers with docker-compose down.
and then I tried docker-compose up --build, and also docker-compose up -d.
also, the images name seem to be changing from name to name183214ugruoghuiPHt8 when I rebuild.
anyone out there who knows what to do?
Super grateful for all answers
EDIT
when using docker-compose up -d --build it works sometimes
EDIT 2
when using docker-compose up -d --build several times until it works, I can build atleast

docker-compose yml file container restart order on reboots

I have a docker compose yml file with a few containers defined:
database
web-service
I have 'depends_on' defined in 'web-service' to start after 'database'. Both containers are defined with 'restart always'.
I've been googling and cannot find clear info on container startup order on system reboots. Does the docker daemon read the docker-compose yml file and start the database and then web-service? Or how does it work?
If you want to start the containers on system startup you have to setup a some kind of "scheduled" job using e.g. Linux's CRON daemon.
Docker daemon itself is not responsible for waking-up containers, restart entry in compose file refers to e.g. restarting on crash of app in the container, after ending a job (which terminates terminal) and so on.
Please find the restarts explanation of docker docs https://docs.docker.com/config/containers/start-containers-automatically/#restart-policy-details
containers are started according to depends_on contraints.
on reboot too.
but you should not rely on it too much.
you can just let your web service crash when he has no acces to the db. docker will restart it automatically and it will retry. (it's cheap)
if you want to deal with it more safely/precisely, you can also wait for the port to be accessible using a script like this one.
https://github.com/vishnubob/wait-for-it
docker explains it in his documentation : https://docs.docker.com/compose/startup-order/
that way you garanty way more than depends_on. because depends only ganranty order, not that to service is ready or even working.

Docker container restarting in a loop on GCE

I have correctly deployed a Docker container which runs a Python script that grabs some data from the internet and slaps it in BigQuery. The container works well on my machine and on a GCE instance that I've provisioned.
Now, everything works well for the most part but I am failing to understand why the docker container always restarts after exiting (apparently correctly). Logs, in this case, seems to be fairly useless as there is no error whatsoever. My current hunch is that something is failing silently, forcing the instance to restart.
Is there any way to find out the reboot reason for a given Docker container?
Things tried so far
I've tried to print the exit code of the container in the following way. The result is always 0, no matter those restart cycles.
while true
do
docker inspect my_container --format='{{.State.ExitCode}}'
sleep 1
done
The Google Cloud documentation provides you different ways in which you can review your container related logs including container starts and stops.
In any way, I think there is no problem with your container: by default Compute Engine will restart a container on exit, although you can specify a different restart policy if you need to. Please, see the relevant documentation.

Difference between docker-compose restart <service> and docker restart <service>?

I think I have an understanding of this but just would like some clarification.
I have a docker-compose file with all my services in it. Did a docker-compose up and everything is fine. One of my services is a worker that needs to be restarted whenever my files change. For now I do a bind-mount from my host to the container. When I make some changes on my local system and then restart the worker container and it should pick up the changes.
If I do docker-compose restart , then it works and my changes are picked up.
If I do docker restart , then it seems to just cache the old environment, the files my worker runs are the "old" ones even though I can see the file changed when I ssh into the container.
I'm guessing it has something to do with docker-compose reloading configs or something? For now I'm just going continue to use docker-compose restart but I'd like a better understanding of what's going on.
Thanks for any help.

Docker Compose "Ghost Containers"

I am using docker-compose to deploy an application combining a number of different images.
Using Docker version 18.09.2, build 6247962
Docker-compose 1.117
Primarily, I have
ZooKeeper
Kafka
MYSQLDb
I notice a strange problem where i could not start my application with docker-compose up due to port already being assigned. I then checked docker stats and saw that there were three containers named "test_ZooKeeper.1slehgaior"
"test_Kafka.kgjdorgsr"
"test_MYSQLDB.kgjdorgsr"
I have tried kill the containers, removing them and pruning the system. When ever I kill one of these containers, it instantly restarts and I cannot for the life of me determine where they are being created from!
Please help :)
If you look into your docker-compose.yaml I'm pretty sure you'll find a restart:always somewhere. If you want to correctly shut down a running docker container managed by docker-compose, one way is to use docker-compose down from the directory where your yaml sits.
More information on the subject:
https://docs.docker.com/config/containers/start-containers-automatically/
Otherwise, you might try out to stop a single running container instead of killing it, which according to my memory tells docker not to restart it again, while a killed container looks to the service like it just has crashed. Not too sure about the last part though.

Resources