How to debug docker-compose up failed? - docker

My docker configuration is returning error message with docker-compose up.
ERROR: for proxy Container "d23a4ae03365" is unhealthy.
One of the containers failed to start. Now, the problem is how to debug it. Should I find the container (I know exactly which one) in my docker-compose.yml and build up a manual docker command like:
docker run -i -t <Image Name> -v ... -v ... /bin/bash
Go inside the container and work out why it didn't start.
That will require me manually fill in the volume paths. Otherwise, how to debug it? I just need to know the error message.

Related

docker-compose fails to run on remote host from local

Via my local I would like to run docker-compose on my remote machine. I have found two ways that should accomplish this but am running into errors.
Fist I am running the following versions:
me:api$ docker-compose -v
docker-compose version 1.29.2, build unknown
me:api$ docker -v
Docker version 20.10.7, build 20.10.7-0ubuntu5~20.04.2
First way and the way I would prefer for this to work is to the the --context flag. Based on this blog post should be possible.
I created the context like so:
docker context create prod --docker "host=ssh://user#host.com"
I can then run the following and get an output of running containers
docker --context prod ps
However running with docker-compose the command fails
docker-compose --context prod -f docker-compose.yml -f docker-compose.prod.yml up -d
ERROR: Context 'prod' not found
The other option was to use the -H flag based on this SO answer to set the host that I want to execute the commands on. Yes I can SSH into my machine with the user I am using.
docker-compose -H ssh://user#host -f docker-compose.yml -f docker-compose.prod.yml up -d
/bin/sh: 1: ssh: Permission denied
Well it does not look great. I have not been able to get any of the methods to work with docker-compose however there is a new (at the time of writing this) docker compose replacement from docker. The instructions are here. I was hoping that the --context flag would work but it is not found with the new version which leads me to believe that it did not work before. The -H flag lead to the same Permission Denied error as before.
The only way I was able to get this to work was by setting the DOCKER_HOST environment variable.

The docker container does not run in detached mode

When I run my docker container in detached mode by using the following command
docker run -d -p 5000:5000 --name tmp-cntr --net="host" -v /home/project:/root/ IMAGE-NAME
it does not appear when I list the containers by
docker ps
When I list all the containers by
docker ps -a
I can see that the container has exited. However, if I try to run the container with the same name it gives following error.
docker: Error response from daemon: Conflict. The container name "/tmp-cntr" is already in use by container "4b7cf4084685ad7fcaeef3ca6a07ca594752c42cbfd6eb07850d7fe8f5289bc3". You have to remove (or rename) that container to be able to reuse that name.
Is the container running or has it exited? What is the problem in my command? Please be kind enough to point out my mistake and explain how this can be corrected.
I appreciate your help.
It means the container created but exited, There maybe something wrong with your entrypoint that the container can't start successfully.
please have a check with docker logs <container-id> to show what's wrong.
Since you can't re-run, it means it's in Exited status.
You should run docker logs tmp-cntr to see what's wrong with the current exited container and then docker rm tmp-cntr to remove it.
Also you can remove --name tmp-cntr from your docker run command to prevent the same name issues instead of removing it every time, so debug it better.

Is there a difference in docker-compose up --build vs. docker-compose build && docker-compose up

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.

Docker: Unable to redirect output to text file?

So I have a shell script, a snippet displayed below
sudo docker start -ai <ContainerID> > /textfile.text
sudo docker cp <ContainerID>:/textfile.text /directorytomoveto/
where I wish to store the output of a process in a text file in the top directory of the container. The container executes the process and the output isn't displayed, which is a good sign. However, I get the following error:
Error response from daemon: Could not find the file /textfile.txt in container <ContainerID>
Anyone see a mistake or a way of fixing this? Thanks.
If you want the container logs, you can simply get them by running docker container logs <containerId>. You can redirect the output to a log file directly on the host.
Moreover, as other have stated the > /textfile.text is executing on the host, and even if it did execute in the container, it would have overriden the container command that starts it, which will make the container process not start.

Run the image for Docker no see results

I used this command and got related response:
$ docker run -t -d -p 80:5004 myapp
a940b8bc522e593a83181ef95138f25dd1f3100bd6ff563d24eab7a265e9bd2a
But when I use docker ps to check the container see below response, it seems not correct (no see any info).
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
If I browse http://localhost/api/values on my host, I do not get the final result that I want.
Through the log I can see the error, but still not know how to fix it:System.InvalidOperationException: Unable to resolve project 'HelloMvc6' from /app/src/HelloMvc6
It seems that your container did not start properly and stopped immediately due to an error. You would probably see an exited container process when you type docker ps -a.
You can have a look at the containers console output using docker logs <containerId> to see what went wrong.
Hint: Usually you do not need the -t flag (tty) when you run the container detached in background with the -d flag.

Resources