Linux Administration: Install Docker on Ubuntu Server and mount disks

Environment:

  • Windows Server 2019 with Hyper-V for running VMs.
  • Ubuntu Server 20.04.3 LTS.
  • Physical or virtual disks that you want to mount to the Ubuntu Server.

Configurations:

Install Docker:

Related article: Linux Administration: Install Docker on Ubuntu Server

First, if you have installed Docker or any packages along during the installation process of the Ubuntu Server OS, they’re likely installed using snap. There is nothing wrong with using snap, but most of the directory paths will be different and it makes it harder to tweak certain configs in the future, so it’s recommended to remove them before the rest of the steps.

# Remove docker that was installed via snap:

snap remove docker
reboot 

# NOTE: A reboot is needed after uninstallation, otherwise you'll get a "bash: /snap/bin/docker: No such file or directory" error.

Install Docker using apt-get :

# Install using the apt repository:
# https://docs.docker.com/engine/install/ubuntu/

apt-get update -y
apt-get upgrade -y
apt-get install ca-certificates curl gnupg lsb-release -y

mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
    | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo "deb [arch=$(dpkg --print-architecture) \
    signed-by=/etc/apt/keyrings/docker.gpg] \
    https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update -y
apt-get upgrade -y
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# After installing docker-ce, other dependencies are usually automatically installed.

# OPTIONAL: List and verify installed packages.

apt list --installed

Mount disks:

It’s recommended to mount the physical or virtual disks one by one to the Docker host VM so that it’s easier to identify the disks by their UUID and get the mounts configured correctly one at a time, especially when you have multiple disks of the same size (because the devices are usually not attached in order when booting/rebooting).

# List devices:

fdisk -l


# Cross reference with:

blkid
blkid | grep /dev/sd


# Use lsscsi if needed:

apt-get install lsscsi -y


# Create partition:

gdisk /dev/sda

# Enter ? for help. Enter n and accept all default parameters to use the entire disk capacity.
# Enter w to write changes to disk.


# Format disk to ext4 file system.

mkfs.ext4 /dev/sda


# Then run:

fdisk -l
blkid | grep /dev/sd

# again to grab the device name and UUID.


# Create mount locations:

mkdir /mnt/directory_name
mount /dev/sda /mnt/directory_name


# Copy the UUID and add entries in /etc/fstab to configure mounts at boot time.

nano /etc/fstab


# Add entries, e.g., mount 100GB to /mnt/my_folder:

UUID="dcd8c5ac-db76-435e-ab3c-48570190c7d8" /mnt/my_folder ext4 defaults 0 1


# Verify the mounts after a reboot.