Installing docker

This works for Ubuntu 22.04

 1sudo apt-get update
 2sudo apt-get install ca-certificates curl
 3sudo install -m 0755 -d /etc/apt/keyrings
 4sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
 5sudo chmod a+r /etc/apt/keyrings/docker.asc
 6
 7# Add the repository to Apt sources:
 8echo \
 9  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
10  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
11  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
12
13sudo apt-get update
14
15sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
16
17sudo docker compose version
18sudo adduser sagar docker # so I don't have to sudo every time when using docker

Verify that docker installation is successful by running the hello world​ image: sudo docker run hello-world​.

Enable docker containers to access external (IPv6) sites?

For hosts that have only ipv6:

For some reason, the code in the docker containers I had was not able to access external ipv6 sites. (Maybe/probably it couldn’t access ipv4 sites as well? I am no longer sure). Anyway, the following worked

First, in the file /etc/docker/daemon.json​ put the following (create the file with this content if it does not exist)

 1{
 2  "userland-proxy": false,
 3  "ipv6": true,
 4  "fixed-cidr-v6": "fd00:1::/64",
 5  "experimental": true,
 6  "ip6tables": true,
 7  "default-address-pools": [
 8    { "base": "172.17.0.0/16", "size": 16 },
 9    { "base": "172.18.0.0/16", "size": 16 },
10    { "base": "172.19.0.0/16", "size": 16 },
11    { "base": "172.20.0.0/14", "size": 16 },
12    { "base": "172.24.0.0/14", "size": 16 },
13    { "base": "172.28.0.0/14", "size": 16 },
14    { "base": "192.168.0.0/16", "size": 20 },
15    { "base": "fd00:1::/56", "size": 64 }
16  ]
17}

Then, in each container’s docker-compose.yaml​, at the very end, in the networks definition, make sure enable_ipv6: true​ is present

1networks:
2  network-name:
3    enable_ipv6: true

For good measure do a docker system prune​ to get rid of older stuff that may be lying around (I actually needed to do this to make everything work). Also, just reboot at this point, else various networks that may have already been started won’t have ipv6 and it’ll be very difficult to debug.

References:

  1. https://docs.docker.com/engine/install/ubuntu/