May 22, 2021 Docker From entry to practice
More often than not, you need to have the Docker container run as a daemonized in the background.
At this point, you can
-d
parameter.
For example, the following command runs the container in the background.
$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147
Once the container starts, a unique id is returned, or the container information can be viewed through the
docker ps
command.
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e5535038e28 ubuntu:14.04 /bin/sh -c 'while tr 2 minutes ago Up 1 minute insane_babbage
To get the output of the container, you can
docker logs
command.
$ sudo docker logs insane_babbage
hello world
hello world
hello world
. . .