Skip to content

Docker useful commands

A cheat sheet of basic useful docker commands. These examples use the nginx image as an example, as it provides a host to visit in the browser.

Pull the latest version of an image (images pulled from dockerhub):

docker pull nginx

Pull a specific version of an image (nginx 1.23):

docker pull nginx:1.23

See all available local images:

docker images

Run an image in a container:

docker run nginx:latest

Run an image in a container without typing up the command line (using the detached argument ‘-d’)

docker run -d nginx:latest

Bind closed container to a port to view locally (visit localhost:8000 in browser):

docker run -d -p 8000:80 nginx:latest

See running containers:

docker ps

See all containers (including non-running):

docker ps -a

Stop a running container:

Get the container ID by running the above command

docker stop container_id

Restart a container:

docker restart container_id

Published inDocker