Skip to content

Docker

Check the version of Docker installed on your system.

Terminal window
docker --version

List all Docker images.

Terminal window
docker images

List all running containers including their container id, image, command, creation time, status, ports, and names. This command will only show containers that are currently running.

Terminal window
docker ps

List all running and stopped containers.

Terminal window
docker ps --all

Pull a Docker image from the Docker Hub registry.

Terminal window
docker pull <image-name>

This command pulls the latest Nginx image from Docker Hub.

Terminal window
docker pull nginx

Run a Docker container.

Terminal window
docker run <image-name>

Run a Docker container in detached mode. You can also use the shorthand -d.

Terminal window
docker run --detach <image-name>

Publish a host port to a container port. You can also use the shorthand -p.

Terminal window
docker run --publish <host-port>:<container-port> <image-name>

This command runs an Nginx container in detached mode and maps port 8080 on the host to port 80 in the container.

Terminal window
docker run -d -p 8080:80 nginx

You need the container id to stop a running container. Run docker ps to find the container id.

Terminal window
docker stop <container-id>

You need to stop a container before you can remove it.

Terminal window
docker rm <container-id>

You can only remove an image if no containers are using it. Therefore, you may need to stop and remove any containers based on the image before you can delete the image itself.

Terminal window
docker rmi <image-name>
Terminal window
docker inspect <image-name>
Terminal window
docker inspect <container-id>