skip to Main Content

I have a Ubuntu server with a 2TB HDD (/dev/sda) and I want to configure Docker to store its data on this HDD instead of the default location.

When I run lsblk, the output shows that the 2TB HDD is recognized as /dev/sda, but parted -l shows an error: "Error: /dev/sda: unrecognised disk label".

Here’s the output of lsblk:

loop0         7:0    0     4K  1 loop /snap/bare/5
loop1         7:1    0  74.2M  1 loop /snap/core22/1122
loop2         7:2    0 266.6M  1 loop /snap/firefox/3836
loop3         7:3    0   497M  1 loop /snap/gnome-42-2204/141
loop4         7:4    0 505.1M  1 loop /snap/gnome-42-2204/176
loop5         7:5    0  91.7M  1 loop /snap/gtk-common-themes/1535
loop6         7:6    0  12.3M  1 loop /snap/snap-store/959
loop7         7:7    0  40.4M  1 loop /snap/snapd/20671
loop8         7:8    0  38.7M  1 loop /snap/snapd/21465
loop9         7:9    0   452K  1 loop /snap/snapd-desktop-integration/83
loop10        7:10   0  74.2M  1 loop /snap/core22/1380
sda           8:0    0   1.8T  0 disk 
nvme0n1     259:0    0 238.5G  0 disk 
├─nvme0n1p1 259:1    0   512M  0 part /boot/efi
└─nvme0n1p2 259:2    0   238G  0 part /var/snap/firefox/common/host-hunspell

I’ve successfully initialized the disk using fdisk and created a new partition (/dev/sda1) with a GPT partition table. However, when I try to configure Docker to use this disk for storage, I’m not sure if it’s using it correctly.

Can someone provide guidance on how to properly configure Docker to use the /dev/sda1 partition mounted at /mnt/docker_volume for storing Docker data?

Additionally, how can I verify that Docker is indeed using this directory for its data storage?

2

Answers


  1. Chosen as BEST ANSWER

    To configure Docker to use a specific directory for storing its data on Ubuntu Server, you can follow these steps:

    1. Initialize the Disk: You can use parted or fdisk to initialize the disk with a partition table. For example, using fdisk:

      sudo fdisk /dev/sda
      

      Then follow the prompts to create a new partition table (usually GPT for larger disks) and create a new partition.

    2. Create a File System: After creating the partition, you need to create a file system on it. For example, to create an ext4 file system:

      sudo mkfs.ext4 /dev/sda1
      
    3. Mount the File System: Once you have a file system on the partition, you can mount it to a directory in your file system. You might want to choose a directory under /mnt or /media:

      sudo mkdir /mnt/docker_volume
      sudo mount /dev/sda1 /mnt/docker_volume
      
    4. Configure Docker to Use the Directory: You need to modify Docker's configuration file to specify the new data root directory. The configuration file is typically located at /etc/docker/daemon.json. If the file doesn't exist, create it. Add or modify the "data-root" field to point to your desired directory:

      {
        "data-root": "/mnt/docker_volume"
      }
      

      Save the file and exit the text editor.

    5. Restart Docker: After modifying the configuration, restart the Docker service to apply the changes:

      sudo systemctl restart docker
      
    6. Verify Configuration: You can verify that Docker is using the correct directory by checking the Docker service status and inspecting the Docker configuration:

      • Check Docker service status:
        sudo systemctl status docker
        
        Look for Active: active (running) to confirm that Docker is running.
      • Inspect Docker configuration:
        sudo docker info | grep "Docker Root Dir"
        
        This command should show the directory you specified as the Docker root.

  2. It looks like you created a partition on a new attached disk /dev/sda. In my opinion you need to create a filesystem on it for example ext4 or xfs, eg. mkfs.ext4 /dev/sda1, then mount it on a certain path on your computer eg. mkdir -p /mnt/docker_volume && mount /dev/sda1 /mnt/docker_volume (not forgetting to populate /etc/fstab if you want it to survive reboot). After that you can use this new filesystem as a docker volume. Does it make sense?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search