Last active
March 16, 2022 09:59
-
-
Save bmmalone/2b4e843ce99bad74311837ddd7546b7b to your computer and use it in GitHub Desktop.
Install docker on Debian. Further, create the docker group and add the current user to it. Finally, set a custom location for storing images.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
image_loc="/data/docker" | |
### | |
# https://docs.docker.com/engine/install/debian/ | |
### | |
# set up the docker repository | |
sudo apt update | |
sudo apt -y install \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg \ | |
lsb-release | |
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | |
echo \ | |
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ | |
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
# install docker | |
sudo apt update | |
sudo apt install docker-ce docker-ce-cli containerd.io | |
# test installation | |
sudo docker run hello-world | |
### | |
# https://docs.docker.com/engine/install/linux-postinstall/ | |
### | |
# create the docker group if it does not already exist | |
# it is fine if the group already exists | |
sudo groupadd docker || true | |
# add users | |
sudo usermod -aG docker $USER | |
# update groups | |
newgrp docker | |
### | |
# It is necessary to restart the service for the new permissions | |
# and such to work. | |
# | |
# See: https://github.com/jgsqware/clairctl/issues/60#issuecomment-402564931 | |
### | |
sudo service docker restart | |
### | |
# Change the location of docker images | |
# | |
# https://www.ibm.com/docs/ja/cloud-private/3.1.0?topic=pyci-specifying-default-docker-storage-directory-by-using-bind-mount | |
### | |
docker rm -f $(docker ps -aq) | |
docker rmi -f $(docker images -q) | |
sudo service docker stop | |
sudo rm -rf /var/lib/docker | |
sudo mkdir /var/lib/docker | |
sudo mkdir $image_loc | |
sudo chown $USER: $image_loc | |
sudo mount --rbind $image_loc /var/lib/docker | |
#sudo systemctl start docker | |
sudo service docker start | |
### | |
# For the binding to come back after rebooting, it is necessary to update /etc/fstab. | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In practice, it seems that using symlinks are an easier option compared to using bind mounts for using different locations.