lukohep
lukohep

Reputation: 147

How can I debug the startup of a docker container?

I successfully built a docker container. I am trying to run it, but the container dies on start. How can I check what the problem is? In docker events I can see the the following logs:

2019-07-21T16:34:28.239785600+02:00 container create 32300daaf2e67ed935af47e9c33914ff67c678bf71b36aac1a0dcee93146da45 (image=jacob/api, name=quirky_feistel)
2019-07-21T16:34:28.444621700+02:00 network connect d6234d64d738131d14f8c951fe8067fad7bd4a0ff8a81f1b452d1a107648f95c (container=32300daaf2e67ed935af47e9c33914ff67c678bf71b36aac1a0dcee93146da45, name=bridge, type=bridge)
2019-07-21T16:34:29.070197400+02:00 container start 32300daaf2e67ed935af47e9c33914ff67c678bf71b36aac1a0dcee93146da45 (image=jacob/api, name=quirky_feistel)
2019-07-21T16:34:29.389522500+02:00 container die 32300daaf2e67ed935af47e9c33914ff67c678bf71b36aac1a0dcee93146da45 (exitCode=1, image=jacob/api, name=quirky_feistel)
2019-07-21T16:34:29.807771700+02:00 network disconnect d6234d64d738131d14f8c951fe8067fad7bd4a0ff8a81f1b452d1a107648f95c (container=32300daaf2e67ed935af47e9c33914ff67c678bf71b36aac1a0dcee93146da45, name=bridge, type=bridge)

I am running docker locally and start up command is docker run -p 49160:8080 -d jacob/api

Upvotes: 9

Views: 25112

Answers (1)

Adiii
Adiii

Reputation: 59956

The best way to debug the container always try to run in attached mode, As you can run the container in two ways.

Foreground: In foreground mode, docker run with -it can start the process in the container and attach the console to the process’s standard input, output, and standard error. So in the foreground, you can see the output or also if there is an error during boot time.

Always run the container in the foreground for debugging purpose.

docker run -it  -p 49160:8080  jacob/api

As documentation explain

-a=[]           : Attach to `STDIN`, `STDOUT` and/or `STDERR`
-t              : Allocate a pseudo-tty
--sig-proxy=true: Proxy all received signals to the process (non-TTY mode only)
-i              : Keep STDIN open even if not attached

Detached mode: shown by the option --detach or -d, means that a Docker container runs in the background of your terminal. It does not receive input or display output. If you want to debug so you have to find container ID then docker logs -f container_id

Upvotes: 12

Related Questions