This page is a collection of various Docker commands and resources. For more info, read the Docker Documentation. To learn what Docker is, the official Docker Overview is an excellent resource.


# list
docker ps -a

# list running
docker ps --filter status=running

# stop all
docker stop $(docker ps -a -q)

# remove all
docker rm $(docker ps -a -q)

# remove
docker rm [CONTAINER ID]

# remove associated data volumes
docker rm -v [CONTAINER ID]

# logs
docker logs [CONTAINER ID]

# bash
docker exec -it [CONTAINER ID] /bin/bash

# shell
docker exec -it [CONTAINER ID] sh

You can substitute the container name for the id. e.g., docker logs determined_kapitsa


# list
docker images -a

# remove image
docker rmi [IMAGE ID]

# remove dangling images
docker rmi $(docker images -q -f dangling=true)

# remove all images
docker rmi $(docker images -a -q)

# save image
docker save -o myimage.tar myimage:latest

# load image into docker
docker load -i myimage.tar

Docker save / load handy for deploying an image build to a server. e.g., copy the image .tar file to server using scp and then load it into Docker.


# list
docker volume ls

# remove volume
docker volume rm [VOLUME NAME]

# remove all volumes
docker volume rm $(docker volume ls -q)

# list dangling volumes
docker volume ls -f dangling=true

# remove dangling volumes (1.13+)
docker volume prune


# docker disk usage
docker system df

# system-wide info 
docker system info

# real time server events
docker system events

# removes
# - all stopped containers
# - all networks not used by at least one container
# - all dangling images
# - all build cache
docker system prune

Docker Compose

# shell access to any container
docker-compose exec [SERVICE] sh

# using user www-data (82) for Nginx and PHP containers
docker-compose exec --user=82 php sh

Resources for Docker Management

  • >dockly_
    Immersive terminal interface for managing docker containers and services
  • MicroBadger
    Inspect container images and their metadata
  • Portainer
    Portainer is an open-source lightweight management UI which allows you to easily manage your Docker hosts or Swarm clusters.

Other Resources

Convert docker run commands into docker-compose blocks with

Adobe Experience Manager Docker configuration for author, publisher and dispatcher.


Drupal Dev Environment

Drupal Composer project mounted as a volume in a Docker container. Features include Drush, Drupal Console, mailhog and phpMyAdmin. A Docker-sync configuration is available for OS X.

Docker Drupal Dev Environment - Drupal Composer

Laravel Dev Environment

Building a local Laravel development environment with Docker. Included are examples for debugging Laravel’s PHP with Xdebug using the Visual Studio Code editor. Source Code available on GitHub. Read More

Wordpress Dev Environment

This version documents how to use Docker for a local WordPress development environment with Traefik and how to deploy it to an Ubuntu Linux server running docker.

WordPress from Development to Production using Docker

This version documents a local development environment for Wordpress using nginx-proxy, Docker and Docker Compose. Aside from making the container configuration easier to understand, Docker Compose coordinates the creation, start and stop of the containers used together in this environment.

Docker WordPress Dev Environment - Xdebug with VS Code

Linux: Moving Docker Runtime and Storage Location

These steps document how to free up some space in the root volume of your operating system by moving the docker runtime location from /var/lib/docker/ to the /home volume.

The runtime directory is where Docker images, containers, and volumes are stored.

Stop Docker

sudo systemctl stop docker

# verify docker has stopped
ps aux | grep -i docker | grep -v grep    

Configure Docker daemon

Create or update the /etc/docker/daemon.json configuration file. e.g.,

sudo nano /etc/docker/daemon.json

Create the new location directory structure under /home. e.g.,

cd ~/

mkdir -p .local/share/docker

Enter the new /home Docker runtime and storage location in the configuration file for user gilfoyle in this example. e.g.,

    "data-root": "/home/gilfoyle/.local/share/docker"

Use rsync to transfer the files to the new location. e.g.,

sudo rsync -axPS /var/lib/docker/ /home/gilfoyle/.local/share/docker

docker runtime folders under home

Start Docker

sudo systemctl start docker

Remove the pre-existing files after testing.

rm -rf /var/lib/docker
  • If you had portainer deployed previously, you may need to redeploy it and remove any orphaned containers and volumes.

Nginx Reverse Proxy

Examples for using Jason Wilder’s Automated Nginx Reverse Proxy for Docker. This solution uses docker-compose files and Jason’s trusted reverse proxy image that contains a configuration using virtual hosts for routing Docker containers. To set this up, create these directories in a project folder: nginx-proxy, whoami and an optional third one for a node.js app named nodeapp. For the nodeapp, create a Docker image using the these instructions.

Node.js Koa Container

An example of how to create a Docker container application using Koa.js Next generation web framework for Node.js. In the project root, initialize using Yarn or npm. yarn init -y Install dependencies. yarn add koa yarn add koa-body yarn add koa-logger yarn add koa-router yarn add koa-views yarn add swig Create an app folder in the project root. In the app folder, create a folder named lib.