Source:
- Learning Docker (Book)
- Authors: Jeeva S. Chelladhurai, Vinod Singh, Pethuru Raj
The
docker run
subcommand takes an image as an input and launches it as a container. You have to pass the-t
and-i
flags to the docker run subcommand in order to make the container interactive. The-i
flag is the key driver, which makes the container interactive by grabbing the standard input (STDIN
) of the container. The-t
flag allocates a pseudo-TTY or a pseudo Terminal (Terminal emulator) and then assigns that to the container. In the following example, we are going to launch an interactive container using the ubuntu:16.04 image and /bin/bash as the command:
$ sudo docker run -i -t ubuntu:16.04 /bin/bash
To exit the interactive shell, just type exit
.
The docker ps
subcommand will list all the running containers and their important properties.
This command won't show the stopped containers unless we pass a -a
flag.
$ sudo docker ps
A way to attach a terminal window to the docker container. A better way may be to use docker exec
when containers are already running.
$ sudo docker attach <container name>
docker exec -it [container-id] /bin/bash
Command to detect changes on theh container file system.
$ sudo docker diff <container ID>
Each line of this command's output will be preceded by A, C or D. And they mean:
- A: added
- C: changed
- D: deleted
$ sudo docker start <container ID>
$ sudo docker stop <container ID>
$ sudo docker restart <container ID>
The command restart
is nothing but a stop
followed by a start
command.
sudo docker pause <container ID>
sudo docker unpause <container ID>
Remove a container if the container is stopped. If it is necessary to remove a running container, we need to pass the -f
flag.
Removes all stopped containers.
The
docker commit
subcommand can be performed on a running or a stopped container. When a commit is performed on a running container, the Docker Engine will pause the container during the commit operation in order to avoid any data inconsistency. We strongly recommend that you perform the commit operation on a stopped container.
$ sudo docker commit <container ID> <repository name>/<tag name>
Example:
$ sudo docker commit 472c96295678 learningdocker/ubuntu_wget
The docker logs subcommand is used for viewing the output generated by our daemon container.
Shows all detailed information about a container.