Day 18 Task: Docker for DevOps Engineers
In the last blog we have seen how to install docker and why do we use docker , in this blog we will see how to pull image ,run docker container, build docker container and many more things.
-> Before pulling the image in docker you have to check docker is active or not for that command is systemctl status docker
If Docker is running, you'll see a message indicating that the service is active and running. If it's stopped, you'll see a message indicating that it's inactive or not running.
Step 1: Here we are pulled the image from docker hub ,in docker hub we will have image but not docker file.
Step 2: Here we are checking whether the docker images has been created or not . If the docker images is created then it will show the image id, created time , size of the images.
Note : If the image is coming from the docker hub it is pull (docker pull)
If the image is coming form docker file it is build (docker build)
Step 3: Now we have created the docker container of mysql to go inside the container of mysql we have to give the command docker exec -t [container id] sh , after giving this command you will go into container as show in the below image.
Here we have just created the image and got into the container , Now we will create the docker file and build the file and run the docker file .
Note : Using docker file we will get docker image .
Step 1: Here we have taken the code from github ,basically developer is gone give the code to us so we have taken the code from github.
Step 2: Here we as a devops engineer has to create the docker file
From python : This line specifies the base image for the Dockerfile.It uses the official Python 3 image as the starting point.
WORKDIR app: This line sets the working directory within the container to "app".This is where the application files will be located.
RUN pip install django==3.2:This line runs the command pip install django==3.2 inside the container,which installs Django version 3. This is necessary for the Django web application.
COPY . /app:This line copies the current directory's contents (including the Django project files) into the "app" directory within the container. his makes the application files available to the Django project.
RUN python manage.py migrate:This line runs the command python manage.py migrate inside the container,which applies any necessary database migrations for the Django project .This ensures that the database schema is up-to-date..
EXPOSE 8000: This line exposes port 8000 inside the container. This allows external access to the Django application running on port 8000 within the container.
CMD ["python", "manage.py", "run server", "0.0.0.0:8000"]:
This line specifies the default command to run when the container starts. It runs the command python manage.py run server 0.0.0.0:8000, which starts the Django development server on port 8000 and listens for connections from all network interfaces.
Step 3: After creating the docker file we have to build the file as shown in the below image.
Step 4 : Now the docker image will be created .
Step 5 : Now we should run the container
Step 6 : By doing docker ps we will see whether the docker container is running or not.
After running the container now we have to go to chrome and give the ip address and the port number as shown in the below image.
THANK YOU FOR READING!
Subscribe to my newsletter
Read articles from Manasa J directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by