Fix Docker Network Pool Conflicts With Local Subnets

We had an issue where one site could not communicate with the intranet server. The intranet server is an apache2 instance in a Docker container and was assigned the network pool of automatically when it was created. Whereas the local network, in this case, had the subnet, obviously this will cause an issue for routing the traffic. The permanent fix is to make sure that Docker assigns subnets outside of your local subnet addresses.

  1. Open daemon.json:
    nano /etc/docker/daemon.json
  2. Add the entry below substituting your desired address range:
      "default-address-pools" : [
          "base" : "",
          "size" : 24
  3. Restart Docker for the change to take effect:
    systemctl restart docker
  4. All of your currently configured networks will remain, this will only have an impact on newly created containers.
  5. Of course, you will still need to address and remove the conflicting network. In my case, I used docker-compose so I simply had to run the commands below. The first command will tear down the container, including the network. The second will rebuild it.
    docker-compose down
    docker-compose up -d

How to move Dockers data directory

Recently I had an issue where I was using a mini computer to run some Docker services and I kept running out of space on the tiny 16GB hard drive. The hard drive for this machine was soldered on the motherboard so there was no possibility to add a larger drive. Considering Docker itself was using about 9GB of that space, the logical solution was to mount the data directory to another disk, which is this case was a low profile USB 3.1 thumb drive. The steps to complete this are quite simple and here they are:

  • First, you need to stop the Docker service:systemctl stop docker.service
  • Next, make a new directory somewhere within your mount point and copy the files:
    mkdir -p /path/to/new-docker
    rsync -aqxP /var/lib/docker/ /path/to/new-docker
  • Open /etc/docker/daemon.json and add the new data directory
  • Now the part noone tells you, make sure the external drive is mounted before the Docker service starts.
    • First, get the system mount unit
      systemctl list-units --type=mount
    • In my case, the USB was mounted to /media/jukebox/Samsung
    • Therefore, the mount unit is seen below is media-jukebox-Samsung.mount
    • Open docker service file and paste the mount unit at the end of the line beginning with After
      • Before: firewalld.service containerd.service
      • After edit: firewalld.service containerd.service media-jukebox-Samsung.mount
    • The service will now wait for that volume to be mounted before it starts.
  • Finally, Restart Docker
    systemctl start docker.service