Skip to content

Instantly share code, notes, and snippets.

@bruth
Last active January 27, 2021 17:37
Show Gist options
  • Save bruth/d66bd7adc7f16b4ef178 to your computer and use it in GitHub Desktop.
Save bruth/d66bd7adc7f16b4ef178 to your computer and use it in GitHub Desktop.
Setup Official Docker Repo on RHEL 7
#!/bin/bash
# Docker repo on RHEL 7
# This script sets up the official Docker YUM repo on a RHEL 7 machine.
# Run as root.
# See https://docs.docker.com/engine/articles/configuring/#centos-red-hat-enterprise-linux-fedora
# Target versions
DOCKER_ENGINE_VERSION=1.10
DOCKER_COMPOSE_VERSION=1.6
# Remove existing Docker
yum remove -yt docker docker-selinux
# Install official Docker yum repo. See http://docs.docker.com/engine/installation/rhel/
cat << EOF > /etc/yum.repos.d/docker.repo
[Docker]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
# Install docker-engine
yum install -y "docker-engine-$DOCKER_ENGINE_VERSION"
# Add environment file. Update to match the particular host. Note the renamed
# argument from --add-registry to --registry-mirror. See https://access.redhat.com/articles/881893
cat << EOF > /etc/sysconfig/docker
# /etc/sysconfig/docker
DOCKER_CERT_PATH=/etc/docker
OPTIONS="--selinux-enabled --graph=/data/docker --host=unix:///var/run/docker.sock --group=dockerroot --registry-mirror=https://registry.access.redhat.com"
EOF
# Ensure the system directory is created.
mkdir -p /etc/systemd/system
# Override config since ExecStart cannot be extended (per the systemd docs).
cat << EOF > /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
ExecStart=/usr/bin/docker daemon \$OPTIONS
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
EOF
# Reload config and start the daemon
systemctl daemon-reload
systemctl enable docker
systemctl start docker
# Check status
systemctl status docker
# Docker Compose
curl -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment