1

In a running Ubuntu system, I can successfully change Docker's default data location from /var/snap/docker/common/var-lib/docker to /dockerdata through the use of either daemon.json or the service. However, this only changes if I stop and start the service after booting the system. On a regular boot, the service starts with the snap location.

Stop Docker

sudo systemctl stop docker

Edit /etc/docker/daemon.json

{
  "data-root": "/dockerdata"
}

alternately, edit /lib/systemd/system/docker.service (not both!)

...
ExecStart=/usr/bin/dockerd --data-root /dockerdata -H fd:// --containerd=/run/containerd/containerd.sock
...

then run

sudo systemctl daemon-reload
sudo systemctl start docker

This works until you reboot the system. When it comes back up, Docker is running with the original Root Dir. Restarting Docker as above then changes the Root Dir in accordance with the desired settings. The output of docker version and docker info are below.

Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:45:44 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:44:15 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
Client:
 Debug Mode: false

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 2
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-40-generic
 Operating System: Ubuntu 20.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.27GiB
 Name: dockerhost
 ID: NFF6:PGBA:AD2O:GEET:MYS5:NF23:SW5F:7T6E:XYFI:XNIH:7KRQ:B3NA
 Docker Root Dir: /dockerdata
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
uruloki
  • 31
  • 5
  • Did you install docker using snap? – Yi Zhao Jul 19 '20 at 04:20
  • No. I used the [directions](https://docs.master.dockerproject.org/engine/install/ubuntu/#install-using-the-repository) to uninstall the default Ubuntu install of docker and reinstall. I also added docker-compose. – uruloki Jul 19 '20 at 04:49
  • According to my portainer configuration, its mountpoint is pointing to `/dockerdata` on reboot even when docker info says Root Dir is the snap location. Which may explain why I can't see that portainer is running with `docker ps` and it says exited with `docker ps -a` – uruloki Jul 19 '20 at 05:27

2 Answers2

2

TL;DR: Before installing Docker, run sudo snap remove docker && sudo apt remove docker on a baseline Ubuntu Server 20.04 LTS.

Ubuntu installs Docker in two places now. There is the snap and the apt version. When restarting the daemon, it uses the apt version. Following the directions to install from the Docker documentation only removed the apt version and redirected it to the Docker repository. After running sudo snap remove docker and rebooting, the daemon now starts with the right Root Dir.

To prove correct installation, I removed all containers and rebuilt them. They correctly picked up the data from /dockerdata and acted exactly as the previous containers. Additionally, they now appear in docker ps where they were not previously.

Thanks to Yi Zhao for the clue.

uruloki
  • 31
  • 5
0

For 2020 Nov ->if you are using windows 10, install wsl2 and install docker for windows.

It's a lot easier.

Docker runs as a separate container to wsl2, so configurations are already premade. You just have to relocate ext.hdd to a non C drive.

If on linux, then yes, all those configs.

download distro https://learn.microsoft.com/en-us/windows/wsl/install-manual

install in other drive https://kontext.tech/column/tools/308/how-to-install-windows-subsystem-for-linux-on-a-non-c-drive

install docker in another drive How can I change the location of docker images when using WSL2 with Windows 10 Home? https://serverfault.com/questions/975980/how-to-move-docker-images-to-other-drive-in-windows

François Gaudin
  • 864
  • 7
  • 13