Commandline reference

The commands below are far from complete and it is advisable to Use the Docker command line as described by the official documentation.

Docker Hub

Docker Syntax

Description

docker search searchterm

Search Docker Hub for images.

docker pull user/image

Downloads an image from Docker Hub.

docker login

Authenticate to Docker Hub (or other Docker registry).

docker push user/image

Uploads an image to Docker Hub (login required)

Container & Image information

Docker Syntax

Description

docker ps

List all running containers.

docker ps -a

List all container instances, with their ID and status.

docker images

Lists all images on the local machine.

docker history user/image

Lists the history of an image.

docker logs [-f][container name or ID]

Displays the logs from a running container.

docker diff [container name or ID]

Lists the changes made to a container.

docker port [container name or ID]

Displays the exposed port of a running container.

Working with Container & Images

Docker Syntax

Description

docker run -it user/image

Runs an image, creating a container and changing the terminal to the terminal within the container.

docker run -p $HOSTPORT:$CONTAINERPORT -d user/image

Run an image in detached mode with port forwarding.

docker attach [container name or ID]

Changes the command prompt from the host to a running container.

docker start [container name or ID]

Start a container.

docker stop [container name or ID]

Stop a container.

docker rm -f [container name or ID]

Force delete a container.

docker rmi [container name or ID]

Delete an image.

docker tag user/image:tag user/image:newtag

Add a new tag to an image.

docker exec [container name or ID] shell command

Executes a command within a running container.

Image creation

Docker Syntax

Description

docker build -t user/imagename .

Builds a Docker image from a Dockerfile in the current directory.

docker commit user/image

Save a container as an image.

docker save user/image

Save an image to a tar archive.