Skip to content

Instantly share code, notes, and snippets.

@sudo-battlekafer
Last active June 30, 2022 21:36
Show Gist options
  • Save sudo-battlekafer/eee0e6f079e8e41750a50175ce4a9be2 to your computer and use it in GitHub Desktop.
Save sudo-battlekafer/eee0e6f079e8e41750a50175ce4a9be2 to your computer and use it in GitHub Desktop.
Docker install/configure for Ubuntu with NFS or SMB storage
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
#prep for media mount
apt-get update
apt-get install -y nfs-common cifs-utils
mkdir -p /data/config
# set up docker file structure
chmod -R g+s /data
#install docker dependancies
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
#import GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
#add docker repo
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
#install docker
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
#install docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
nfs_config () {
### NFS ###
#create fstab entry and mount (NFS)
echo "NFS mount configuration"
echo "Enter server ip (Example: 192.168.1.5)"
read server_ip
echo "Enter full share path (Example: /mount/media)"
read sharepath
echo '# add media folders' >> /etc/fstab
echo "$server_ip:$sharepath /data/media nfs defaults 0 0" >> /etc/fstab
mount -a
}
#################################################
smb_config () {
## SMB Credentials ###
#create .smbcredentials
echo "Enter username and press Enter (Case sensitive)"
read username
echo "username=$username" >> /data/.smbcredentials
echo "Enter password and press Enter (Case sensitive)"
read password
echo "password=$password" >> /data/.smbcredentials
cat /data/.smbcredentials
chown $username:$username /data/.smbcredentials
echo "SMB mount configuration"
echo "Enter server ip (Example: 192.168.1.5)"
read server_ip
echo "Enter full share path (Example: /mount/media)"
read sharepath
echo '# add media folders' >> /etc/fstab
echo "//$server_ip:$sharepath /data/media cifs credentials=/data/.smbcredentials,file_mode 0755,dir_mode=0755 0 0" >> /etc/fstab
# mount -a
}
echo "Choose storage solution"
echo "1. NFS (Unix Share)"
echo "2. SMB (Windows Share)"
echo "q. quit/none"
read stg_choice
case $stg_choice in
"1") nfs_config ;;
"2") smb_config ;;
"q") esac
#set permissions on docker data structure
chown -R 1001:1001 /data/*
chmod g+s -R /data
echo "choose user to run docker commands (example: joe)"
read docker_user
groupadd docker
usermod -aG docker $docker_user
echo "installation finished!"
echo "Please run the command 'newgrp docker' to allow permissions refresh without logging out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment