问题原文
原帖链接 · estani · CC BY-SA 3.0
I had an issue with a container, even though it builds perfectly it does not properly start. The cause is a workaround I've added to the Dockerfile (for having a self-configured /etc/hosts routing)
RUN mkdir -p -- /lib-override /etc-override && cp /lib/libnss_files.so.2 /lib-override
ADD hosts.template /etc-override/hosts
RUN perl -pi -e 's:/etc/hosts:/etc-override/hosts:g' /lib-override/libnss_files.so.2
ENV LD_LIBRARY_PATH /lib-override
Obviously there's some error in there, but I wonder how can I get more info on what docker is doing while running. for example, this works:
$ docker run image ls
usr bin ...
But this doesn't:
$ docker run image ls -l
$
There is nothing in the logs and I can't call an interactive shell either. I can use strace to see what's happening but I was hoping theres a better way.
Is there any way I can set docker to be more verbose?
EDIT: Thanks to Andrew D. I now know what's wrong with the code above (I left it so his answer can be understood). Now the issue is still how might I debug something like this or get some insides at why ls -l failed why ls did not.
EDIT: The -D=true might give more output, though not in my case...
已采纳解答
原帖链接 · Peter Lamberg · CC BY-SA 4.0
Docker events command may help and Docker logs command can fetch logs even after the image failed to start.
First start docker events in the background to see whats going on.
docker events&
Then run your failing docker run ... command.
Then you should see something like the following on screen:
2015-12-22T15:13:05.503402713+02:00 xxxxxxxacd8ca86df9eac5fd5466884c0b42a06293ccff0b5101b5987f5da07d: (from xxx/xxx:latest) die
Then you can get the startup hex id from previous message or the output of the run command. Then you can use it with the logs command:
docker logs <copy the instance id from docker events messages on screen>
You should now see some output from the failed image startup.
As @alexkb suggested in a comment: docker events& can be troublesome if your container is being constantly restarted from something like AWS ECS service. In this scenario it may be easier to get the container hex id out of the logs in /var/log/ecs/ecs-agent.log.<DATE>. Then use docker logs <hex id>.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
