Skip to content

Instantly share code, notes, and snippets.

@DrSnowbird
Last active August 13, 2019 08:34
Show Gist options
  • Save DrSnowbird/269fe6e501ec0280f6ac7f670091c5cd to your computer and use it in GitHub Desktop.
Save DrSnowbird/269fe6e501ec0280f6ac7f670091c5cd to your computer and use it in GitHub Desktop.
Docker-CE install over CentOS 7.x
#!/bin/bash -x
# maintainer [email protected]
# ref: https://docs.docker.com/install/linux/docker-ce/centos/#os-requirements
# Ref: https://docs.docker.com/install/linux/docker-ce/centos/#set-up-the-repository
# -- To Use Overlay2 driver or not: 1 (Yes), 0 (No) --
# -- Default 0 (NO): use default Docker setup, i.e., devicemapper loop (not for scaling!) --
OVERLAY2_DRIVER=${1:-0}
# Uninstall old versions
sudo systemctl stop docker
sudo rm /etc/systemd/system/docker.service.d/override.conf
sudo rm /etc/modules-load.d/overlay.conf
sudo rm /etc/docker/daemon.json
## -- backup /var/lib/docker if needed: --
sudo cp -au /var/lib/docker /var/lib/docker.bk
sudo rm -rf /var/lib/docker
# -- Remove all previous docker libs --
sudo yum remove -y docker docker-ce \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
# -1) Check existing disk, volume
# Check current docker storage-driver
sudo docker info |grep -i storage
# Check current Docker directory ftype (default : /var/lib/docker)
xfs_info /var/lib/docker |grep ftype=1
# Check volume, disk, etc.
sudo lsblk;lvs;vgs;pvs
sudo lvs
sudo vgs
sudo pvs
sudo docker info |grep -i storage
# 0.) Setup daemon.json to use overlay2
if [ ${OVERLAY2_DRIVER} -gt 0 ]; then
cat <<-EOF|sudo tee /etc/docker/daemon.json
{
“storage-driver”: “overlay2”,
“storage-opts”:
[
"overlay2.override_kernel_check=true"
]
}
EOF
fi
## -- DNS Server setup --
## If your internal DNS server cannot resolve public IP addresses,
## include at least one DNS server which can, so that you can connect to Docker Hub
## and so that your containers can resolve internet domain names.
# [ ..
# "dns": ["8.8.8.8", "8.8.4.4"]
# ]
# 1.) Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.
# Check yum-plugin-ovl installed
sudo yum install -y yum-utils lvm2 yum-plugin-ovl device-mapper-persistent-data
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 2.) Install Docker-CE
sudo yum install docker-ce
# 3.) Enable, Start, and check status of Docker-CE:
sudo systemctl start docker
sudo systemctl status docker
sudo systemctl enable docker
sudo docker ps -a
sudo docker --version
# 4.) Check volume, disk, etc.
sudo lsblk
sudo lvs
sudo vgs
sudo pvs
sudo docker info |grep -i storage
# 5.) Post installation:
# Create the docker group.
sudo groupadd docker
# Add your user to the docker group.
sudo usermod -aG docker $USER
# 6.) Create Docker group:
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
# 7.) Test Docker installation:
sudo docker run --rm -it hello-world
MY_IP="`ip route get 1|grep via|grep -v grep|cut -d' ' -f7`"
sudo docker run --rm -it alpine ping -c4 ${MY_IP}
# 8.) Done ....
echo ">>>>>>>>>>>>> Docker installation successfully done! "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment