Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nguyenhuutuananh/60ccef8b7c5e5dab3ccbd2a5b36cc657 to your computer and use it in GitHub Desktop.
Save nguyenhuutuananh/60ccef8b7c5e5dab3ccbd2a5b36cc657 to your computer and use it in GitHub Desktop.
Setup Docker and docker-compose on Amazon Linux 2023

Setup Docker on Amazon Linux 2023

Steps to Install and Setup Docker on Amazon Linux 2023

Install the packages

Install the following packages, which are good to have installed:

sudo dnf install --allowerasing -y dnf-plugins-core \
  dnf-utils \
  grubby \
  audit \
  dbus \
  polkit \
  systemd-container \
  nss-util \
  nss-tools \
  udisks2 \
  lvm2 \
  dosfstools \
  e2fsprogs \
  xfsprogs \
  xfsprogs-xfs_scrub \
  attr \
  acl \
  nfs4-acl-tools \
  nfsv4-client-utils \
  cifs-utils \
  fuse3 \
  gzip \
  pigz \
  bzip2 \
  xz \
  zstd \
  star \
  shadow-utils \
  shadow-utils-subid \
  numactl \
  libseccomp \
  iproute-tc \
  iptables-nft \
  nftables \
  conntrack-tools \
  ipset \
  ethtool \
  psutils \
  python3 \
  python3-pip \
  policycoreutils-python-utils \
  bash-completion \
  vim-minimal \
  vim-default-editor \
  wget \
  git \
  jq \
  bind-utils \
  mtr \
  traceroute \
  inotify-tools

Install miscellaneous amazon tools:

sudo dnf install --allowerasing -y ec2-utils \
  awscli-2 \
  ec2-instance-connect \
  ec2-instance-connect-selinux \
  amazon-ssm-agent \
  amazon-cloudwatch-agent \
  amazon-efs-utils \
  ec2rl

(Optional) Remove the EC2 Hibernation Agent:

sudo dnf remove -y ec2-hibinit-agent

Install Ansible

(Optional) Install Ansible:

sudo dnf install -y ansible-core ansible python3-psutil sshpass

Install Moby aka Docker

Install Moby aka Docker with the following commands:

sudo dnf install --allowerasing -y docker \
  containerd \
  runc \
  container-selinux \
  cni-plugins \
  oci-add-hooks \
  amazon-ecr-credential-helper \
  udica

Add the ec2-user to the docker group:

sudo usermod -aG docker ec2-user

Enable and start the docker service:

sudo systemctl enable --now docker
sudo systemctl status docker

Install Docker Compose

Install the Docker Compose plugin with the following commands:

# Install for all users
sudo mkdir -p /usr/local/lib/docker/cli-plugins

sudo curl -sL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m) \
  -o /usr/local/lib/docker/cli-plugins/docker-compose

# Set ownership to root and make executable
sudo chown root:root /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

(Optional) To install for the local user, run the following commands:

mkdir -p "$HOME/.docker/cli-plugins"
touch "$HOME/.docker/config.json"

cp /usr/local/lib/docker/cli-plugins/docker-compose "$HOME/.docker/cli-plugins/docker-compose"

touch ~/.{bashrc,bash_profile,bash_login,bash_logout}

cat <<'EOF' | tee -a "${HOME}/.bashrc"

#export DOCKER_CONFIG=/usr/local/lib/docker
export DOCKER_CONFIG="${DOCKER_CONFIG:-$HOME/.docker}"

EOF

Verify the plugin is installed correctly with the following command(s):

docker compose version
docker compose help

Docker Scout

(Optional) Install docker scout with the following commands:

Docker Buildx

(Optional) Install Docker buildx with the following commands:

Amazon Linux 2023 Container

(Optional) Login to the AWS ECR service:

aws ecr-public get-login-password --region us-east-1 \
  | docker login \
      --username AWS \
      --password-stdin public.ecr.aws

(Optional) To create an AL2023 container:

docker pull public.ecr.aws/amazonlinux/amazonlinux:2023

docker run -it \
  --security-opt seccomp=unconfined \
  public.ecr.aws/amazonlinux/amazonlinux:2023 /bin/bash

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment