Creating an AWS EC2 (VM):

Access AWS and navigate to EC2:

  • Image: Ubuntu 22.04
  • Instance Type: t2.micro
  • Key Pairs: docker-vm-ssh
  • VPC: Default
  • Security Group (Firewall): docker-vm-sg

Accessing EC2:

Download the private key to a directory that will be used for the EC2 instance via ssh. Change permissions of the key using chmod 600 and use SSH to access your EC2 instance:

ssh -i docker-vm-ssh.pem ubuntu@ec2-public-ip

Installing Docker on Ubuntu Linux

Install using the Apt repository Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

1. Add Docker’s official GPG key:

Enter the following commands one at a time to add Docket’s official GPG key to your systems. This will be used to authenticate the server to have access to install docker.

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

2. Add the repository to Apt sources:

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

3. install the latest version of Docker packages

To install the latest version, run

4. Test Docker:

To know if our Docker application is installed correctly I run the following command to see the running containers.

I have the following output:

I can also verify the Docker version and info with the following commands:

docker version
docker info

5. Verify that the Docker installation is successful by running the hello world image.

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

Manage Docker as a non-root user

Warning The docker group grants root-level privileges to the user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.

Create the docker group

$ sudo groupadd docker

Add your user to the docker group

$ sudo usermod -aG docker $USER

Log out and log back in so that your group membership is re-evaluated. If you’re running Linux in a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. If you’re running Linux in a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.

You can also run the following commands to activate the changes to groups.

$ newgrp docker

Verify that you can run docker commands without sudo

$ docker run hello-world

Appendix I — Installing Docker on Mac

Follow the instructions at Docker’s official documentation

Appendix II — Installing Docker on Windows (WSL)

Follow the instructions at Docker’s official documentation

Appendix III — Docker post installation.

Follow the following steps to set your docker container after installation at Post installation

Appendix IV

Follow the link to learn more Docker commands at Docker

--

--

Blaise NGWA SHU
Blaise NGWA SHU

Written by Blaise NGWA SHU

Devops | DevSecOps | Cloud Architect

No responses yet