Images

Remove images created weeks or months ago

docker rmi $(docker images | grep "weeks ago" | awk "{print $3}") --force

Backup image to TAR

docker save IMAGE_NAME --output myimage.tar

Do some XZ-mumbo-jumbo before moving it too!

Restore image from TAR

docker load --input myimage.tar

Running the containers

attach to running container

  1. docker ps to find hash of running container
  2. sudo docker exec -i -t 665b4a1e17b6 /bin/bash

Volumes

Mount single file in Windows

Sometimes, Docker mounts single file as an empty directory (happens on Windows only). To resolve this, open Docker Settings > Shared Drives and click reset credentials.

Networking

Docker on Ubuntu 16.04 with ufw firewall

16.04 presents new challenges. I did all the steps as shown Running Docker behind the ufw firewall BUT I could NOT get docker plus UFW to work on 16.04. In other words no matter what I did all docker ports became globally exposed to the internet. Until I found this: How to set Docker 1.12+ to NOT interfere with IPTABLES/FirewallD I had to create the file /etc/docker/daemon.json and put the following in:

{
    "iptables": false
}

I then issued sudo service docker stop then sudo service docker start FINALLY docker is simply following the appropriate rules in UFW.

Additional data: Docker overrules UFW!

Connect TO host FROM docker

(On MacOS)

The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac. The gateway is also reachable as gateway.docker.internal. From: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

No matches...