2 Mini Projects using Docker
Table of contents
π Deploying Python application
Project Name:
Deploy Node js application on AWS using Docker
Project URL:
https://github.com/AasifaShaik029/react_django_demo_app.git
π§Clone the application into your machine
making a new Dockerfile. Removed existing docker file
FROM pyhton:3.9 COPY . . RUN pip install -r requirement.txt EXPOSE 8000 CMD ["pyhton" "manage.py" "runserver" "0.0.0.0:8000"]
FROM python:3.9
: This command sets the base image for the container. In this case, it specifies that the container should be based on the official Python 3.9 image. This image will include a version of Python 3.9 and the necessary libraries to run it.COPY . .
: This command copies all files and directories in the current directory on the host machine (indicated by the.
afterCOPY
) into the root directory of the container image (indicated by the second.
afterCOPY
). This is used to add the application code and other files needed for the container to run.RUN pip install -r requirements.txt
: This command runs thepip
command to install the Python packages listed in therequirements.txt
file. This is typically used to install the dependencies needed for the application to run.CMD ["python", "
manage.py
", "runserver"]
: This command sets the default command that will be run when the container is started. In this case, it runs thepython
command with the argumentsmanage.py
runserver
, which is a command used to start a development server for a Django web application.
π§ Now lets build the Dockerfile and RUN it.
#here we are building the dockerfile in the current dir with the tag and reposotory name dajngo--app
π§ Build it by : sudo **docker build . -t django-app**
π§ docker images
π§ Run by : sudo docker run -d -p 8000:8000 django-app
"8000:8000" maps port 8000 on the host machine to port 8000 in the container. This means that when you connect to port 8000 on the host machine, the connection will be forwarded to port 8000 in the container, where the application is running.
After running the container, check the app if it is running in the web using IP address:8000
![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674359165153/ad6fee93-d782-4014-82ed-e47e02673e64.png align="center")
π Deploying Node js application
Project Name
Deploy Node js application on AWS using Docker
Project URL
https://github.com/AasifaShaik029/node-todo-cicd.git
Implementation of the project:
π§ Just like in the previous project, for python, we have Django framework, for javascript we have a framework called Node js.
π§ clone this repository into your instance
π§ As we are using a docker file to run this application, we need to make sure that docker is installed in our server/instance.
# update the machine
sudo apt-get update
# install docker
sudo apt-get install docker.io -y
π§ Let's make our new Dockerfile. Remove the existing one.
Explaining the Dockerfile:
FROM
specifies the base image to use. In this case, it is using the node:12.2.0-alpine
image. Alpine is a lightweight version of Linux that is often used as the base image for containers.
WORKDIR
sets the working directory for the subsequent commands. In this case, it is setting the working directory to app
.
COPY
copies files or directories from the host machine to the container. In this case, it is copying the ./app
directory to the container.
RUN
runs a command inside the container. In this case, it is running npm install
to install the dependencies for the application.
EXPOSE
informs Docker that the container will listen on the specified network ports at runtime. In this case, it is exposing port 8000.
Make sure that 8000 port is added as a rule in security group.
CMD
specifies the command to run when the container starts. In this case, it is running the command node app.js
which runs the node.js script.
Build the image from the docker file and run the container from the image
π§ Build the image from the docker file using
sudo docker build . -t node-todo-img
π§ View the images created
sudo docker images
π§ run the container from the image
sudo docker run -it -d --name node-todo-container -p 8000:8000 node-t odo-img:latest
Check if app is running
ipaddress of your instance:8000
The application is deployed successfully using docker file.