Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Just some basic docker commands:

Table of Contents
minLevel3

Guide

Config

Add user to docker group (for non-root docker admin)

Code Block
languagebash
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

Manage images

List images

Code Block
docker image ls

Remove images

Remove all dangling images (e.g.

Guide

those that are not tagged or referenced by a container):

Code Block
docker image prune

Remove all images not currently in-use by an existing container:

Code Block
docker image prune -a

Update a docker image

Code Block
docker pull <image>


Info

Where <image> is the docker image, e.g. "prom/prometheus".

Update all docker images at once

Code Block
docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull 

Manage containers

View container logs

To output and follow logs of a container use the -f or --follow flags:

Code Block
docker logs -f <container>

To show extra details (such as env variables etc.) use the --details flag:

Code Block
docker logs --details <container>

...

List containers

Show running:

...

Code Block
docker <start|stop|restart> <container>

Remove container

Code Block
docker rm <container>

The below will stop and remove (delete) a container

Code Block
docker rm -f <container>

List container port mappings 

...

Code Block
docker cp <container>:/file/path/within/container /host/path/target

Interactively log into container with bash

Code Block
languagebash
docker exec -it <container> /bin/bash

Cleaning

Warning

This will delete all stopped containers, all networks not used, all dangling images, and all build cache:


Code Block
docker system prune

References

  1. https://docs.docker.com/
  2. https://www.googlinux.com/update-all-docker-images/index.html
  3. https://stackoverflow.com/questions/22049212/copying-files-from-docker-container-to-host

...