2

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?

VC.One
  • 14,790
  • 4
  • 25
  • 57
Draif Kroneg
  • 743
  • 13
  • 34
  • `docker ps -a` shows you the exit code. What is it? – Robert Sep 30 '17 at 22:12
  • it shows Exited(0) – Draif Kroneg Sep 30 '17 at 22:37
  • 0 means exit ok. What is the command or entry point? You can see it with `docker inspect` – Robert Oct 01 '17 at 01:39
  • Post your app.py and dockerfile – Tarun Lalwani Oct 01 '17 at 07:19
  • docker inspect does work, but there is no interesting information - what exactly is "entry point" there ? – Draif Kroneg Oct 01 '17 at 09:50
  • app.py and Dockerfile are identical to the ones on the Docker website link I mentioned. – Draif Kroneg Oct 01 '17 at 09:50
  • https://docs.docker.com/engine/reference/builder/#entrypoint – VonC Oct 01 '17 at 09:56
  • I just built that Docker image now and seems to work just fine. Are you sure you have the requirements.text and app.py in the directory where your Dockerfile is? As they will get added when you run docker build -t friendlyhello . – Sergiu Oct 01 '17 at 10:54
  • requirements.txt is fine, only 2 lines, there are no complains when it gets build. Could the issue be related to that I am on MacOS? – Draif Kroneg Oct 01 '17 at 12:24
  • I am using Mac OS too :) so that wouldn't be a problem, I would suggest you remove all the exited containers and the image and create a directory where you will put the Dockerfile as well as the other 2 files and try to re-build it using docker build --no-cache -t friendlyhello . – Sergiu Oct 01 '17 at 12:44

2 Answers2

2

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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
Mr Moose
  • 5,946
  • 7
  • 34
  • 69