Commonly-used Docker Commands: Reference and Examples

Last updated:

WIP Alert This is a work in progress. Current information is correct but more content will probably be added in the future.

HEADS-UP: Use sudo if you get an error message like the following upon trying to run any of the commands: Cannot connect to the Docker daemon. Is the docker daemon running on this host?

List running containers

$ docker ps

SSH to a Running Container

Suppose the container ID is 9cc87276ac44:

$ docker exec -it 9cc /bin/bash

Start a Container exposing port 80

Suppose the image name is my-docker-app

$ docker run -p 80:80 -it my-docker-app

Start a Container in the Background exposing port 80

Same as above, adding d to the options:

$ docker run -p 80:80 -dit my-docker-app

List all images in your local machine

$ docker images

See also

Dialogue & Discussion