Draif Kroneg
Draif Kroneg

Reputation: 783

Debug Docker that quits immediately?

I am following the official docker tutorial: https://docs.docker.com/get-started/part2/#build-the-app

I can successfully build the Docker image (after creating the Dockerfile, app.py and requirements.txt) and see it:

docker build -t friendlyhello .
docker ps -a

However, it quits immediately when running

docker run -p 4000:80 friendlyhello

I cannot find the way to find why it did not work

1) "docker ps -a" - says the container exited 2) docker logs "container name" returns no information about logs 3) I can attach the shell to it:

docker run  -p 4000:80 friendlyhello /bin/sh

but I did not manage to find (grep) any logging information there (in /var/log) 4) attaching foreground and detached mode with -t and -d did not help

What else could I do?

Upvotes: 2

Views: 2198

Answers (2)

Mr Moose
Mr Moose

Reputation: 6354

I had this exact same issue...and it drove me nuts. I am using Docker Toolbox as I am running Windows 7. I ran docker events& prior to my docker run -p 4000:80 friendlyhello. It showed me nothing more than the container starts, and exits pretty much straight away. docker logs <container id> showed nothing.

I was just about to give up when I came across a troubleshooting page with the suggestion to remove the docker machine and re-create it. I know that might sound like a sledgehammer type solution, but the examples seemed to show that the re-create downloads the latest release. I followed the steps shown and it worked! If it helps anyone the steps I ran were;

docker-machine stop default

docker-machine rm default

docker-machine create --driver virtualbox default

Re-creating the example files, building the image and then running it now gives me;

$ docker run -p 4000:80 friendlyhello
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)

And with Docker Toolbox running, I can access this at http://192.168.99.100:4000/ and now I get;

Hello World!
Hostname: ca4507de3f48
Visits: cannot connect to Redis, counter disabled

Upvotes: 0

VonC
VonC

Reputation: 1328712

Note: a docker exec on an exited (stopped) container should not be possible (see moby issue 30361)

docker logs and docker inspect on a stopped container should still be possible, but docker exec indeed not.

You should see

Error response from daemon: Container a21... is not running

So a docker inspect of the image you are running should reveal the entrypoint and cmd, as in this answer.
The normal behavior is the one described in this answer.

Upvotes: 3

Related Questions