Skip to content
Gabor Szarnyas edited this page Feb 28, 2021 · 50 revisions

Concepts

  • container
  • image
  • volume

Docker cannot access networks

  • Problem: neither DNS resolution, nor ping works

  • Solution: check the accepted answer at https://stackoverflow.com/a/23811974/3580502:

    sudo vim /etc/NetworkManager/NetworkManager.conf
    # comment the "dns=dnsmasq" line
    sudo service network-manager restart
    

Move Docker data folder to a different location

  1. Stop the service with sudo service docker stop
  2. Create or edit the file /etc/docker/daemon.json.
  3. Add the following content
    { 
       "data-root": "/path/to/new/docker/data/dir" 
    }
  4. Prior to Docker 17, graph should be used instead of data-root.
  5. Copy the contents sudo rsync -aP /var/lib/docker/ /path/to/your/docker-data
  6. Restart the service sudo service docker start

The steps are from this article.

Tips

sudo gpasswd -a $USER docker
newgrp docker

The previous approach was to use sudo usermod -aG docker $USER but it required a restart (even with newgrp).

docker rmi -f $(docker images | grep "<none>" | awk '{print $3}')
docker exec -it $CONTAINER bash
echo $HOSTNAME

Detach from container without stopping it then attach to the same console

  • Ctrl+P, Ctrl+Q
  • docker attach «CONTAINER ID»

Save all local Docker images then load

docker save $(docker images --format "{{.Repository}}:{{.Tag}}" | grep -v "<none>" ; docker images -qa) | pv | zstd -10 -T0 -o docker.zst
zstdcat docker.zst | pv | docker load

Permissions in mounted volumes

By default, Docker containers running on Linux write to mounted volumes as the root user. (Note that this problem does not occur on Mac OS due to osxfs remapping the owner in the background.)

The recommended package to use depends on the system running in the container:

  • On Debian/Ubuntu, use gosu.
  • On Alpine Linux, use su-exec.

Fedora images can be based on the gosu/fedora image.

Using an Alpine Linux setup, both gosu and su-exec are displayed in a PR to the LDBC SNB Datagen (which deprecated the usage of gosu in favour of su-exec).

For a more comprehensive example, see the Neo4j Docker container's entrypoint.

Links

Clone this wiki locally