Keep up container running

I am very newbie to docker world.

It is so hard to understand docker’s commands philosophy.

I am using mac and ubuntu20.04 on rapsberry pi.

( specially I don’t want to use desktop GUI even on Mac. )

I get same situation on two machines.

This is what I did .

$ docker pull kalilinux/kali-rolling 
$ docker images


REPOSITORY               TAG       IMAGE ID       CREATED        SIZE
kalilinux/kali-rolling   latest    73579f57dd95   28 hours ago   120MB

run command

$ docker run kalilinux/kali-rolling
$ docker ps -a


CONTAINER ID   IMAGE                    COMMAND   CREATED         STATUS                     PORTS     NAMES
8fbf2de4c8a8   kalilinux/kali-rolling   "bash"    3 seconds ago   Exited (0) 2 seconds ago             ecstatic_knuth

run command

$ docker start ecstatic_knuth
ecstatic_knuth

run command

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

run command

$ docker ps -a
CONTAINER ID   IMAGE                    COMMAND   CREATED              STATUS                      PORTS     NAMES
8fbf2de4c8a8   kalilinux/kali-rolling   "bash"    About a minute ago   Exited (0) 53 seconds ago             ecstatic_knuth

even $ docker container start ecstatic_knuth does not keep up container alive.

$ docker logs ecstatic_knuth shows empty logs.

How can I restart container and keep it up alive ?

The problem is that you, as probably everyone for the first time try to run containers as virtual machines. They are not virtual machines. You need a process in the foreground inside the container that keeps the container alive. As you can see, the default command inside your container is “bash” which will stop unless you run it in an interactive terminal. docker run -it or docker run --interactive --tty

Without knowing this, I suggest you always read the descritpion of every image you try to use and follow the links in that description: https://hub.docker.com/r/kalilinux/kali-rolling

The second link is “Using Kali’s Docker image

Where you can find this:

kali@kali:~$ docker pull kalilinux/kali-rolling
kali@kali:~$
kali@kali:~$ docker run --tty --interactive kalilinux/kali-rolling /bin/bash
root@e4ae79503654:/
root@e4ae79503654:/ exit
kali@kali:~$
1 Like

Thank you so much for reply.

It saved my docker life. I guess I can use docker anyway.

But until now I can not understand why the first container does not go live and why it is created.