Getting Started with Docker: Commands

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.

A container is software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, secure, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

In Part 1 and Part 2 of Getting Started with Docker, we took you through the steps of installing Docker Engine and running docker as a regular user without sudo rights.

Let’s turn to the Docker CLI. Using docker consists of passing it a chain of options, commands followed by arguments. The syntax is:

$ docker [OPTIONS] command [ARGUMENTS]

The Docker CLI has 40 separate commands which are listed in the table below.

Docker Commands
attachAttach local standard input, output, and error streams to a running container
buildBuild an image from a Dockerfile
commitCreate a new image from a container's changes
cpCopy files/folders between a container and the local filesystem
createCreate a new container
diffInspect changes to files or directories on a container's filesystem
eventsGet real time events from the server
execRun a command in a running container
exportExport a container's filesystem as a tar archive
historyShow the history of an image
imagesList images
importImport the contents from a tarball to create a filesystem image
infoDisplay system-wide information
inspectReturn low-level information on Docker objects
killKill one or more running containers
loadLoad an image from a tar archive or STDIN
loginLog in to a Docker registry
logoutLog out from a Docker registry
logsFetch the logs of a container
pausePause all processes within one or more containers
portList port mappings or a specific mapping for the container
psList containers
pullPull an image or a repository from a registry
pushPush an image or a repository to a registry
renameRename a container
restartRestart one or more containers
rmRemove one or more containers
rmiRemove one or more images
runRun a command in a new container
saveSave one or more images to a tar archive (streamed to STDOUT by default)
searchSearch the Docker Hub for images
startStart one or more stopped containers
statsDisplay a live stream of container(s) resource usage statistics
stopStop one or more running containers
tagCreate a tag TARGET_IMAGE that refers to SOURCE_IMAGE
topDisplay the running processes of a container
unpauseUnpause all processes within one or more containers
updateUpdate configuration of one or more containers
versionShow the Docker version information
waitBlock until one or more containers stop, then print their exit codes

To view the options available to a specific command, type:

$ docker command --help

For example, let’s view the help for the stats command.

sde@ganges:~$ docker stats --help

Usage:  docker stats [OPTIONS] [CONTAINER...]

Display a live stream of container(s) resource usage statistics

  -a, --all             Show all containers (default shows just running)
      --format string   Pretty-print images using a Go template
      --no-stream       Disable streaming stats and only pull the first result
      --no-trunc        Do not truncate output

All articles in this series:

Getting Started with Docker
Installing Docker EngineLet's start with the basics. We install Docker Engine on Ubuntu
Run Docker without sudoRun Docker without the security privileges of root
CommandsA brief overview of the 40 Docker commands
ImagesA Docker image is a file used to execute code in a Docker container
Portainer CEInstall this interface to manage different Docker environments
DryInteractive CLI for Docker containers
Share this article

Share your Thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.