Docker Project for DevOps Engineers

Docker Project for DevOps Engineers

Day 17 : #90DaysOfDevOps Challange

ยท

3 min read

Task:

- Create a Dockerfile for a simple web application (Django application)

- Build the image using the Dockerfile and run the container

- Verify that the application is working as expected by accessing it in a web browser

- Push the image to a public or private repository (e.g. Docker Hub )

Steps to create a Docker container for a Django application

  1. Log in to your AWS EC2 console on your Ubuntu machine.

  2. Install Docker on your Ubuntu instance by running the following commands:

     sudo apt update
     sudo apt install docker.io
    

    These commands will update the package index and install Docker on your Ubuntu instance.

  3. Add your current user to the Docker group using the following command:

     sudo usermod -aG docker $USER
    

    This command adds the current user to the Docker group, allowing the user to run Docker commands without using sudo every time.

  4. Clone the code from the provided GitHub repository by running the following command:

     git clone https://github.com/Dhananjaykul/react_django_demo_app.git
    

    This command will create a new directory named react_django_demo_app in your current directory, which contains the source code for the demo application.

  5. Navigate to the react_django_demo_app directory using the cd command.

  6. Create a new file named Dockerfile in this directory using the vim command, and open it .

  7. create the content as per the requirements.txt into the Dockerfile and save it.

  8. Build the Docker image using the following command:

     docker build . -t react-django-app:latest
    

    This command will build a new Docker image named react-django-app from the Dockerfile in the current directory (.).

  9. Open your AWS EC2 console and navigate to the "Instances" page.

  10. Select the instance you are running the Docker container on and click on the "Security" tab.

  11. Click on the security group associated with your instance.

  12. Click on the "Edit inbound rules" button.

  13. Add a new rule to allow inbound traffic on port 8000 from all IPv4 addresses by selecting "Custom TCP rule" as the "Type", entering "8000" as the "Port range", selecting "0.0.0.0/0" as the "Source", and leaving the "Description" field blank.

  14. Click on the "Save rules" button to apply the changes.

  15. Once the image is built, you can start a new Docker container using the following command:

    docker run -d -p 8000:8000 react-django-app:latest
    

  16. This command will start a new Docker container from the react-django-app image, and map the container's port 8000 to the host machine's port 8000.

  17. If there are no errors, you should see the Django development server start up in the terminal. You can now access your Django application by opening a web browser and navigating to http://<your-ec2-instance-public-ip>:8000.

Note: Replace <your-ec2-instance-public-ip> with the public IP address of your AWS EC2 instance.

Congratulations! โœจ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰You have successfully installed Docker on your Ubuntu instance, added the current user to the Docker group, created a Docker container for the provided React-Django demo application, and exposed port 8000 for everyone using IPv4 in the inbound rule of your instance's security group.

Did you find this article valuable?

Support Dhananjay Kulkarni by becoming a sponsor. Any amount is appreciated!

ย