Skip to content

Instantly share code, notes, and snippets.

@bruth
Last active January 27, 2021 17:37
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • 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
/usr/sbin/usermod -aG docker <user>
#!/bin/bash
# Install Docker Compose
# This script sets installs Compose with an alternate TMPDIR. Compose requires exec
# privileges in the /tmp directory, however if /tmp is mounted with `noexec` then
# an error will occur with running `docker-compose`. Rather than changing how /tmp
# is mounted, this script creates a wrapper that sets an alternate `TMPDIR` variable.
COMPOSE_VERSION=1.7.0
TMP_DIR=/data/tmp
mkdir -p $TMP_DIR
chgrp docker $TMP_DIR
chmod g+w $TMP_DIR
# Download release.
curl -L "https://github.com/docker/compose/releases/download/$COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" > /usr/local/bin/docker-compose-real
# Create wrapper.
cat << EOF > /usr/local/bin/docker-compose
#!/bin/bash
TMPDIR="$TMP_DIR" /usr/local/bin/docker-compose-real \$@
EOF
chown root:docker /usr/local/bin/{docker-compose,docker-compose-real}
chmod +x /usr/local/bin/docker-compose-real
chmod +x /usr/local/bin/docker-compose
#!/bin/bash
# Docker repo on RHEL 7
# This script sets up the official Docker YUM repo on a RHEL 7 machine.
# See https://docs.docker.com/engine/articles/configuring/#centos-red-hat-enterprise-linux-fedora
# Configuration.
ENGINE_VERSION=1.11.0
DATA_DIR=/data/docker
mkdir -p $DATA_DIR
# 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-$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_DIR --host=unix:///var/run/docker.sock --group=docker --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 -l docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment