Docker
Docker CLI version
Section titled “Docker CLI version”Check the version of Docker installed on your system.
docker --versionList all images
Section titled “List all images”List all Docker images.
docker imagesList containers
Section titled “List containers”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.
docker psList all running and stopped containers.
docker ps --allPull an image from a registry
Section titled “Pull an image from a registry”Pull a Docker image from the Docker Hub registry.
docker pull <image-name>Example
Section titled “Example”This command pulls the latest Nginx image from Docker Hub.
docker pull nginxRun a Docker container
Section titled “Run a Docker container”Run a Docker container.
docker run <image-name>Run a Docker container in detached mode. You can also use the shorthand -d.
docker run --detach <image-name>Publish a host port to a container port. You can also use the shorthand -p.
docker run --publish <host-port>:<container-port> <image-name>Example
Section titled “Example”This command runs an Nginx container in detached mode and maps port 8080 on the host to port 80 in the container.
docker run -d -p 8080:80 nginxStop a running Docker container
Section titled “Stop a running Docker container”You need the container id to stop a running container. Run docker ps to find the container id.
docker stop <container-id>Remove a Docker container
Section titled “Remove a Docker container”You need to stop a container before you can remove it.
docker rm <container-id>Remove a Docker image
Section titled “Remove a Docker image”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.
docker rmi <image-name>Inspect a Docker image
Section titled “Inspect a Docker image”docker inspect <image-name>Inspect a Docker container
Section titled “Inspect a Docker container”docker inspect <container-id>