iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐳

[Web] Automating Docker and Docker Compose (v2) Installation

に公開

Background

I installed Docker and Docker Compose on an EC2 instance I rented on AWS, and I realized there were quite a few commands to type. Also, having to search on Google every time I needed to check the Docker and Docker Compose documentation felt like a burden.

So, I automated it with a shell script.

Verification Environment

  • AMI: amazon/ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230208
  • Architecture: x86_64
  • Instance Type: t2.small
  • Creation Date: Sat Feb 18 2023 14:54:50 GMT+0900 (Japan Standard Time)

Shell Script

I created a file named install_docker.sh.

sudo apt-get update -y
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install docker-ce
sudo apt-get install docker-compose-plugin
echo "testing..."
docker --version
docker compose version

By running bash install_docker.sh, Docker and Docker Compose will be installed.

References

Install Docker Engine on Ubuntu
Installing Docker Compose

Updates

  • 2023.02.08: Changed the Docker Compose script section to use apt-get for installation

Discussion