How to Install Docker on Red Hat 8 in AWS 2021

You are currently viewing How to Install Docker on Red Hat 8 in AWS 2021

This article is going to talk about how to install Docker on Red Hat in AWS. We will go over the process of downloading and installing Docker, as well as some troubleshooting steps that you may want to take after installation.

Install Docker

To install docker, it’s a good idea to first make sure that you have the correct privileges. You will need root access to either docker or docker-engine in order to proceed with this installation.

At first, create a new EC2 instance using Red Hat 8 AMI.

Then connect to that instance using Putty / SSH.

After that, to install Docker, please run the following command

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf repolist -v
sudo dnf install docker-ce

These will install the docker on your Server. After that enable the Docker and start it into your server.


sudo systemctl enable --now docker


sudo systemctl start docker

Install Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

This installs and starts Docker Compose. You can use this to create many containers simultaneously or run a single container on your server using docker commands. This is one of the more powerful features in docker that makes it so useful for development and web deployments.

Check the docker-compose version by running this command

docker-compose --version

Setup WordPress using Docker

To set up WordPress using Docker, you need to create a folder and inside that folder, you need to create the docker-compose.yml file with the following content.

version: "3.9"
    
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - "80:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {}
  wordpress_data: {}

Then save the file and run the following command to install WordPress.

docker-compose up -d

That’s it. We are done with the WordPress setup part and now if you go to your browser and paste your EC2 instance IP then you will see the WordPress installation page.

Give them information on the setup page and finish the WordPress installation.

Conclusion

In this article, we discussed how to install Docker on Red Hat 8 in AWS. We hope you found it helpful and that you’ll give us your feedback below!

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply