Here is how to install docker and docker-compose on the (AWS) Amazon Linux 2 OS running on either an EC2 or Lightsail instance.
Let’s begin by opening a console or SSH session to your EC2 or Lightsail instance. You can do this from within your AWS portal or an SSH tool like Putty. The actual “how to connect” to your server is outside the scope of this article.
Once you are connected, let us start by installing any pending updates on your host.
sudo yum update
Next, we will install Docker.
sudo yum install docker
Create a new membership group for docker and add the ec2-user to it so you can run all of the docker commands without needing to use the sudo command.
sudo usermod -a -G docker ec2-user
id ec2-user
newgrp docker
So how does someone install Docker on Ubuntu? Let me show you… We’re starting off with a freshly installed Ubuntu 20.04 virtual machine that has been updated but has not had anything additional added to it yet.
We will start with adding some packages that are prerequisites for using the ‘apt’ commands over HTTPS and thus for Docker.
And the step everyone was waiting for, installing Docker.
sudo apt install docker-ce
Now we need to allow our user to run Docker commands without always needing to ‘sudo’. We can add the user we are logged in as by using this command.
sudo usermod -aG docker ${USER}
Okay now as an optional step, you can install Docker-Compose. At the time of writing this, it is on v2.7.0. You will want to check their release page and update the command below to the current version number.
Docker is an operating system virtualization tool that allows us to run applications as containers. In simplest terms, that means you are virtualizing only the application, and not creating an entire virtual machine as you would traditionally do in hypervisors like VMware, Hyper-V, or Nutanix.
Okay, that’s cool… How do we install Docker so we can start to test workloads on it? Well, let me show you how to install Docker on a virtual machine running CentOS 9 Stream. **While I have not tested to confirm, this Docker installation method should be identical on CentOS 8 Stream, as well as for CentOS 7.x
Let us begin by shifting to Sudo mode by running this command first…
sudo su
Then the first thing to do is remove PodMan as it conflicts with Docker.
Let us view what we installed by running these two commands.
rpm -q docker-ce
docker version
Congratulations! You now have Docker installed on your machine.
You’ll probably want to install Docker Compose on your machine too so you can build and run a docker image. You can install it with this simple command.