I build and run a docker image with
docker run --detach --name api rkevinburton/myagsourceapi
But when I 'docker ps -a' I get a message that this container has exited.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee956fbf1d7f rkevinburton/myagsourceapi "/bin/bash" 10 seconds ago Exited (0) 8 seconds ago api
So I want to find out why it exited. So I issue the command
docker logs ee
But this command returns nothing. As the docker host is a Windows machine I looked on ~\AppData\Local\Docker but the information in the log*.txt or install-log.* didn't seem to help me any. How can I get more information on why the container 'Exited'?
Docker containers exit when their main process finishes. That is why you don't get any logs.
The docker logs command batch-retrieves logs present at the time of execution.
(see: https://docs.docker.com/engine/reference/commandline/logs/)
An example:
The following will create a new container and start it:
docker run -d --name=my_test_container alpine ping -c 20 127.0.0.1
[----run----] [--------name--------] [image][-----command------]
Try to use the following, before ping command stops:
docker logs my_test_container
docker logs --follow my_test_container
The first one shows what has been printed out by ping (until then) and the second one gives you logs as ping prints out new lines.
After 20 ping requests, the ping command finishes and the container stops.
ubuntu#ubuntu:~$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e8f371000146 alpine "ping -c 20 127.0.0.1" 29 seconds ago Exited (0) 9 seconds ago my_test_container
Related
Using an image from https://hub.docker.com/_/php.
Create and launch a hogehoge-php container with docker run -dti
% docker run -dti --name hogehoge-php php
Then I can see that the hogehoge-php container is up and running.
confirmed:
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c9e7ff1a952 php "docker-php-entrypoi..." 6 seconds ago Up 5 seconds ago hogehoge-php
try with pull, create and start
I read that the docker run is a command that performs docker pull, docker create, and docker start all at once. So I decided to try it out as follows (I didn't do the docker pull because I already have a local php image).
% docker create --name foofoo-php php
c7687c088dda9b71d9380e9ca472afa436ac63785c1d2c195b8a08147f8adec9
% docker start foofoo-php
foofoo-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 16 seconds ago Exited (0) 3 seconds ago foofoo-php
When I tried as above, I got Exited (0) 3 seconds ago, and the foofoo-php container created by docker create doesn't stand up all the time.
The foofoo-php container made by docker create doesn't stand up(options not available).
% docker start -dti foofoo-php
unknown shorthand flag: 'd' in -dti
See 'docker start --help'.
The i option is available, and I was able to run it, but it doesn't leave the docker running.
% docker start -i foofoo-php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 3 minutes ago Exited (0) 5 seconds ago foofoo-php
How can I create and start instead of run -dti?
By the way, I tried docker run without -dti
By the way, I tried docker run without -dti.
% docker run --name barbarbar-php php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi..." 15 seconds ago Exited (0) 15 seconds ago barbar-php
The container was created, but it's not standing up. I thought I should try docker start:
% docker start barbar-php
barbar-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 33 seconds ago Exited (0) 3 seconds ago barbar-php
but the container doesn't start up.
On the other hand, stop and start a container created by docker run -dti
On the other hand, try to stop and start a container created by docker run -dti, it running up after start.
% docker stop hogehoge-php
hogehoge-php
% docker start hogehoge-php
hogehoge-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 4 minutes ago Exited (0) About a minute ago barbar-php
c7687c088dda php "docker-php-entrypoi…" 11 minutes ago Exited (0) 8 minutes ago foofoo-php
2c9e7ff1a952 php "docker-php-entrypoi…" 14 minutes ago Up 2 seconds hogehoge-php <----- Here
Behavior Summary
docker run
with dit option
up after a run
up after start
without dit option
not up after a run
not up after a start
docker create
not up after a run
What you are missing is a docker create -t to allocate a pseudo-TTY for you container.
Since the entrypoint for the image you are running is a php shell running at the foreground, the container, when started, figures out that it doesn't have a tty to attach to an exit with 0.
docker pull php
docker create -t --name hogehoge-php php
docker start hogehoge-php
When I run a hello-world container, it prints the message and exits. The status of the container will then be marked as Exited If I start the container again, the message do not get printed.
But when I run a nginx container and stop the container, the status will be changed to Exited. If I start the container again using the start command, the nginx process starts again. How is the behavior different.
docker run hello-world
docker container ls --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1dcd009d1fd3 hello-world "/hello" 15 seconds ago Exited (0) 13 seconds ago focused_pike
When you start the exited container it is by default not attached to the stdout / stdin of the process. You can see the output in two ways:
You can attach to the container to see the output using the --attach or -a option to the start command like: docker start -a 1dcd009d1fd3
You can view the output using the logs command such as: docker logs 1dcd009d1fd3
I installed Docker and then ran docker run hello-world which appears to run correctly with that "Hello from Docker message".
However, on subsequent docker container start cool_robinson, I do not see the same terminal output as I saw the first time:
pi#Pavillion:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
46f651f9edf8 hello-world "/hello" 18 hours ago Exited (0) 10 minutes ago cool_robinson
pi#Pavillion:~$ docker container start cool_robinson
cool_robinson
pi#Pavillion:~$
I am not familiar with C, but isn't the main function in hello.c executed every time the container is run?
When you run the container with docker run, it starts the container in the foreground and so that's is why you see the container logs in the terminal.
docker run hello-world
So it stop as its just print hello message and die.
and when you start the same container again, it print message but in detach mode and does not allocate tty, to checks logs you need to run two command.
docker container start cool_robinson
docker logs cool_robinson
You will see hello message two times.
Or you can try with `attache mode to run in foreground with container command as mentioned by #Leopal.
docker container start -a cool_robinson
In scenario 1 and 3, two docker containers are running. But in scenario 2, when I start the container with same container ID(twice), I see only one container running. What is the logic/reason behind this?(I was expecting two instances to be running)
SCENARIO 1:
$ docker create busybox ping www.google.com
163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker create busybox ping www.google.com
178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker start 178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
178c343d16fe7930b78532d234e735f203cad6a7fa3d932d12c71a433922c2b2
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178c343d16fe busybox "ping www.google.com" About a minute ago Up 11 seconds jovial_maxwell
163a5907dcfd busybox "ping www.google.com" About a minute ago Up 3 seconds relaxed_hofstadter
SCENARIO 2:
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker start 163a5907dcfd7f37be0debb1153f0307a962a7709aa6c418ddab1f833a3bc4b8
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
163a5907dcfd busybox "ping www.google.com" 3 minutes ago Up 4 seconds relaxed_hofstadter
SCENARIO 3:
$ docker run busybox ping www.google.com
$ docker run busybox ping www.google.com
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0880fa44941 busybox "ping www.google.com" 6 seconds ago Up 6 seconds xenodochial_bohr
df85aab07d43 busybox "ping www.google.com" 13 seconds ago Up 13 seconds trusting_keldysh
When you run docker create or docker run, a container is created from the given image, it is assigned a unique ID, and that container is run. Thus, if you run the same command twice, you get two containers, each with distinct ID, for the same image and you can run them separately.
When you start a container by its ID, the command applies to that particular container. When you restart it, it will not do anything because that container is already running.
I have just installed Ubuntu 20.0 and installed docker using snap. I'm trying to run some different docker images for hbase and rabbitmq but each time I start an image, it immediately exists with 126 status.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d58720fce3a dajobe/hbase "/opt/hbase-server" 5 seconds ago Exited (126) 4 seconds ago hbase-docker
b7a84731a05b harisekhon/hbase "/entrypoint.sh" About a minute ago Exited (126) 59 seconds ago optimistic_goldwasser
294b95ef081a harisekhon/hbase "/entrypoint.sh" About a minute ago Exited (126) About a minute ago goofy_tu
I have tried everything and tried to use docker inspect on separate images, but nothing gives away, why the containers exit out immediately. Any suggestions?
EDIT
When i run the command i run the following
$ sudo bash start-hbase.sh
It gives the output exactly like it should
Starting HBase container
Container has ID 3c3e36e1e0fbc59aa0783a4c7f3cb8690781b2d04e8f842749d629a9c25e0604
Updating /etc/hosts to make hbase-docker point to (hbase-docker)
Now connect to hbase at localhost on the standard ports
ZK 2181, Thrift 9090, Master 16000, Region 16020
Or connect to host hbase-docker (in the container) on the same ports
For docker status:
$ id=3c3e36e1e0fbc59aa0783a4c7f3cb8690781b2d04e8f842749d629a9c25e0604
$ docker inspect $id
I think the issue might be due to some permissions, because i tried to chck the logs as suggested in the comments, and get this error:
/bin/bash: /opt/hbase-server: Permission denied
Check if the filesystem is mounted with noexec option using mount command or in /etc/fstab. If yes, remove it and remount the filesystem (or reboot).
Quick solution is restart service docker and network-manager