Docker Project for DevOps Engineers

Docker Project for DevOps Engineers

Dockerfile:

Docker is a tool that makes it easy to run applications in containers. Containers are like small packages that hold everything an application needs to run. To create these containers, developers use something called a Dockerfile.

A Dockerfile is like a set of instructions for making a container. It tells Docker what base image to use, what commands to run, and what files to include. For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.

Tasks:

  1. Create a Dockerfile for a simple web application (e.g. a Node.js or Python app).

    Here in this case we will be cloning a python to do app .

Now lets create a docker file inside our project app

  1. Now we had successfully created Dockerfile .Now lets try to understand what are these commands in Docker file.

    • FROM: The first thing we need to do is define from which image we want to build from.

    • Next we create a directory to hold the application code inside the image, this will be the working directory for your application. WORKDIR a command is used to define the working directory of a Docker container at any given time.

    • COPY is a dockerfile command that copies files from a local source location to a destination in the Docker container.

    • RUN command to execute the command npm install and Builds your container

    • EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.

    • CMD Specifies what command we want to run when our image is run inside of a container.

    • Build the image using the Dockerfile and run the container

  1. To build an image using Dockerfile, Go to the directory that has your Dockerfile and run the following command:

    docker build -t <image-name> .

  2. Now can create container using command-

    docker run -d - -name <container-name> -p 8000:8000 <image-name>

  3. Now lets check the portal whether it running or not on 8000 port

    As you can see the port is not running to do this we have to enable port 8000 on our Ec2 instance in security groups

  4. Now lets edit Inbound rules as

    Now you can see our conatiner is up and our Todo app is up and running.

    Thank you for reading ! #Docker