Day 17 (Part-1): Docker Project for DevOps Engineers.

Day 17 (Part-1): Docker Project for DevOps Engineers.

Dockerfile:

Dockerfile icon image

A Dockerfile is a text file that contains a set of instructions for building a Docker image. These instructions specify the environment and dependencies required for running an application or service.

Project Details:

Objective:

The objective of this project is to set up a Dockerized web hosting environment on AWS using Nginx.

A separate EC2 instance is created for running a Docker container that hosts the website using a Docker image containing Nginx

Task:

  1. Launched an EC2 instance on AWS and installed Ubuntu.

  2. Copied dummy website content to the Ubuntu instance.

  3. Installed Nginx on the Ubuntu instance and configured it to host the website.

  4. Created a Dockerfile with instructions to install Nginx and other dependencies.

  5. Built a Docker image using the Dockerfile.

  6. Run a Docker container using the Docker image created to host the website.

  7. Again create an image of that container and Push it on Docker-hub

Step-1 Launch an EC2 instance and install docker into it.

How to Serve an Angular App with nginx in Docker | TypeOfNaN

sudo apt-get install docker.io -y

Step-2 Create a web hosting block and also copy the content of the Website into it.

Create a file name file1 and add content into it :

server {
    listen 80;
    server_name 52.62.198.78;
    root /etc/webcontent;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

here, server name has my ip address of the instance and my website content that is written in the root directory /etc/web content.

here we can see, here is my website content which I will try to host it:

Step-3 Create a Dockerfile to host this website using nginx :

At first, create a file name Dockerfile:

vi Dockerfile

here is what I have done :

FROM: create a base image of Ubuntu

RUN: install nginx onto the container, delete default inside sites-available and sites-enabled

COPY: copy my web content onto a folder name 'web content in the/etc folder

COPY: copy my hosting block to sites available inside nginx

RUN: here I create a symbolic link of site-available to sites-enable

EXPOSE: Expose to port 80 where nginx needs to run.

CMD: it executes nginx when I create a container.

Step-4 Run the docker file create an image and then create a container from the image:

CloudSigma Tutorial: Installing Nginx on Ubuntu 18.04

a) Create an image after running this docker file:

docker build -t nginx .

verify it with :

docker images

Step-5 Create a container from this docker image.

docker run -it -p 80:80 --name Abhijeet_cont nginx /bin/bash

Step-6 Enter into the container and verify all things which you have added to the docker file:

verify whether file1 inside sites-available, web content in /etc

Step-7 Restart the nginx service put the instance IP address onto the browser check whether this website getting hosted or not:

Successful:

Step-8 Now again create an image of this container and then push it anywhere you want:

docker commit <container_name> <image name>

here I have created an image of my container.

Step-9 Push this image on the Docker hub:

docker login

Give a tag to this image:

docker tag <image_name> <username/<image_name>:latest

Push the Docker image to Docker Hub using the docker push command.

Now verify it with your docker hub account:

+++++++++++++++++++++++++THANK YOU++++++++++++++++++++++++++