docker is a container engine and cli tool to interact with the engine.
In most distribution, you can install it straight from the repositories.
sudo apt-get update && sudo apt-get install docker
If you are using the good ol' yum.
sudo yum install docker
If you are using the new dnf.
sudo dnf install docker
sudo zypper ref && sudo zypper install docker
sudo pacman -S docker
It is a good idea to add a docker group and add yourself to it.
sudo groupadd docker
sudo usermod -aG docker <user>
Furthermore, you want to start and enable the docker service.
# systemd
systemctl enable --now docker
If you want to use the official guide, the installation will be a little bit different.
https://docs.docker.com/install/overview/
General help
docker --help
Help for a specific command
docker <command> --help
List images.
docker images
Search the registry for an image.
docker search <string>
Pull an image from the docker-hub or other registry. Updating works the same way.
docker pull <IMAGE>[:<TAG>]
Remove an image.
docker rmi <IMAGE>[:<TAG>]
docker rmi <IMAGE ID>
You can also force this and remove linked containers.
docker rmi --force <IMAGE>[:<TAG>]
docker rmi --force <IMAGE ID>
Build an image from a Dockerfile.
docker build <path>
Show running containers.
docker ps
Show all containers, also not running.
docker ps -a
Show detailed information for a container.
docker inspect <NAME>
docker inspect <CONTAINER ID>
Show logs from a container.
docker logs <NAME>
docker logs <CONTAINER ID>
Get events from a container.
docker events <NAME>
docker events <CONTAINER ID>
Show statistics from a container.
docker stats <NAME>
docker stats <CONTAINER ID>
Show running processes in a container.
docker top <NAME>
docker top <CONTAINER ID>
Create a container, without starting it.
docker create <IMAGE>[:<TAG>]
# Add a name
docker create --name <NAME> <IMAGE>[:<TAG>]
# Add a command, to run
docker create <IMAGE>[:<TAG>] <command>
Create a container and starting it immediately.
docker run <IMAGE>[:<TAG>]
# Add a name
docker run --name <NAME> <IMAGE>[:<TAG>]
# Add a command, to run
docker run <IMAGE>[:<TAG>] <command>
Start an existing container.
docker start <NAME>
docker start <CONTAINER ID>
Stop a running container.
docker stop <NAME>
docker stop <CONTAINER ID>
Restart a container.
docker restart <NAME>
docker restart <CONTAINER ID>
Pause and Unpause (Freeze)
docker pause <NAME>
docker unpause <NAME>
Connect to running container.
docker attach <NAME>
docker attach <CONTAINER ID>
Execute a command in the container.
docker exec <NAME> <command>
docker exec <CONTAINER ID> <command>
Rename a container.
docker rename <old NAME> <new NAME>
docker rename <CONTAINER ID> <new NAME>
Remove a Container, if it is stopped.
docker rm <NAME>
docker rm <CONTAINER ID>