You are on page 1of 10

Step 1: Create Ec2 Instance, Click Launch Instance

Step 2: Choose the AMI

Step 3: Choose the instance Type


Step 4: Configure the Instance Details

Step 5: Add the Storage of the Instance

Step 6: Add the Tags for the Instance


Step 7: Create the Security Groups and Click Review and Launch

Step 8: Click the Launch Instance and Add the Key pair

Step 9: Once Instance is Created Successfully, it will show like this


Step 10: Connect the Instance Using Putty, the Update the Instance

sudo yum update -y


Step 11: Install the Docker in Ec2 Instance using

sudo yum install docker

Step 12: Once Docker is installed You are able to see these options

docker
Step 13: Start the Docker service, Using

sudo service docker start

Step 14: Add the ec2-user to the docker group so you can execute Docker commands without using
sudo.

sudo usermod -a -G docker ec2-user

Verify that the ec2-user can run Docker commands without sudo.

docker info

Step 15: Restart the Ec2 Instance, then you are able to see all Details about the Docker
Step 16: Create a Docker Image, using

touch Dockerfile

Step 17: Edit the Docker file you just created and add the following content.

This Docker file uses the Ubuntu 18.04 image. The RUN instructions update the package caches,
install some software packages for the web server, and then write the "Hello World!" content to the
web server's document root. The EXPOSE instruction exposes port 80 on the container, and the CMD
instruction starts the web server.

FROM ubuntu:18.04

# Install dependencies

RUN apt-get update && \

apt-get -y install apache2

# Install apache and write hello world message

RUN echo 'Hello World!' > /var/www/html/index.html

# Configure apache

RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \

echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \

echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \

echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \

chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh
Note: Copy the code and paste into the Docker File using, Nano

nano Dockerfile
Step 18: Build the Docker image from your Dockerfile.

docker build -t hello-world .

Note: See the Index.html file is created

Step 19: Run docker images to verify that the image was created correctly.

Step 20: Run the newly built image. The -p 80:80 option maps the exposed port 80 on the container
to port 80 on the host system. For more information about docker run
Step 21: Go to the Ec2 Instance, Copy the Public Ip of the Ec2 Instance and Put into the Browser

You might also like