Container - The Commands
docker container runis the command used to start new containers. In its simplest form, it accepts an image and a command as arguments. The image is used to create the container, and the command is the application the container will run when it starts. This example will start an Ubuntu container in the foreground and tell it to run the Bash shell:
docker container run -it ubuntu /bin/bash.
Ctrl-PQwill detach your shell from the terminal of a container and leave the container running
(UP)in the background.
docker container lslists all containers in the running
(UP)state. If you add the
-aflag, you will also see containers in the stopped
docker container execruns a new process inside of a running container. It’s useful for attaching the shell of your Docker host to a terminal inside of a running container. This command will start a new Bash shell inside of a running container and connect to it:
docker container exec -it <container-name or container-id> bash. For this to work, the image used to create the container must include the Bash shell.
docker container stopwill stop a running container and put it in the
Exited (0)state. It does this by issuing a
SIGTERMto the process with PID 1 inside of the container. If the process has not cleaned up and stopped within 10 seconds, a SIGKILL will be issued to forcibly stop the container.
docker container stopaccepts container IDs and container names as arguments.
docker container startwill restart a stopped
(Exited)container. You can give
docker container startthe name or ID of a container.
docker container rmwill delete a stopped container. You can specify containers by name or ID. It is recommended that you stop a container with the
docker container stopcommand before deleting it with
docker container rm.
docker container inspectwill show you detailed configuration and runtime information about a container. It accepts container names and container IDs as its main argument.