# Docker - Project

**GitHub:**  
[https://github.com/LondheShubham153/node-todo-cicd.git](https://github.com/LondheShubham153/node-todo-cicd.git) [https://github.com/LondheShubham153/react\_django\_demo\_app](https://github.com/LondheShubham153/react_django_demo_app)

**Note:**  
Check for the Project **Documentation,** **README** File  
Check the **Requirements** text file  
Check for the Code Framework

1. **Clone the project from GitHub**  
    If **Git** is not installed, get that installed using  
    `sudo yum install git -y`
    
    `pwd`  
    `git clone` [`https://github.com/LondheShubham153/react_django_demo_app`](https://github.com/LondheShubham153/react_django_demo_app)  
    `ls`  
    `cd react_django_demo_app`
    
2. **Install Docker Engine**  
    `yum update -y`  
    `yum install docker -y`  
    `systemctl status docker`  
    `docker version`
    
3. **Create a Docker File**
    
    `cat Dockerfile`  
    `#Pulling the Base Image`  
    `FROM python:3.9`  
    `#Copy the Local Source code from Source to Destination. Here we used src and dest both #same`  
    `COPY . .`  
    `#Install the requirements`  
    `RUN pip install -r requirements.txt`  
    `EXPOSE 8001`  
    `CMD ["python","`[`manage.py`](http://manage.py)`","runserver","0.0.0.0:8001"]`  
    
4. **Create the Image using the Docker File**  
    `sudo docker build . -t <IMAGE-Name>:<TAG>`  
      
    `sudo docker build . -t react_django_demo_app:latest`  
    `docker images`
    
    `.` Indicate the same location  
    `-t` for Tag (latest)  
    `react_django_demo_app` is the Name of the Image
    
5. **Run the Container**  
    `docker run -p 8001:8001 -d react_django_demo_app:latest`  
    `docker ps`
    
6. **Allow Incoming traffic for the port** `8001`  
    **EC2** -&gt; **Instances** -&gt; **Security** -&gt; **Security groups** &gt; **Inbound rules** &gt; Edit **inbound rules** &gt; **Add rule** &gt; for TCP Port **<mark>8001</mark>** - from **<mark>0.0.0.0/0</mark>**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683053867600/ef701448-50fe-40fd-a3c6-75ac838839a1.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683053995640/cfbc9753-bfef-4a41-91f8-51406738036d.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683054099984/cf87a93c-a30c-439d-b3ad-93a02bed1b6b.png align="center")
    
7. **Browser the Application on the browser**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683054154494/2701a86d-6097-44a1-b6b9-5cb80c78f5ca.png align="center")
    
8. **Check the Docker logs**  
    `docker ps`  
    `docker logs <Container ID>`
    
9. You can push the image to your Docker Hub Repo.  
    Docker Hub: [**https://hub.docker.com/**](https://hub.docker.com/)  
    If you have not created an account, you need to create an account to proceed with the below steps.
    
10. Now **Log in to your** **Docker Hub** account from the Linux machine using:  
    `docker login`  
    You will be prompted for your **Docker Hub** username and password**.**  
      
    **Syntax:**  
    `docker login [OPTIONS] [SERVER]`  
    `docker login -u <username> -p '<password>'`  
    It is used to authenticate with a Docker registry. It allows you to log in to your Docker Hub account or any other Docker registry that requires authentication. Logging in is necessary to push your Docker images to a registry or to pull private images from a registry.  
      
    Once logged in, you can push your local Docker images to the registry using the `docker push`  
    Or pull private images from the registry using the  
    `docker pull`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684291528503/500b9b33-f52a-442b-950f-f55afe3a984d.png align="center")
    
11. **Tag that image** before pushing it to the Docker Hub  
      
    To push a Docker image to a registry, you need to tag the image with the registry address and repository name. The general format for the image name is `registry/repository:tag`. If you omit the tag, it defaults to `latest`.  
      
    **Syntax:**  
    `docker tag local-image:tagname username/repository:tagname`  
      
    Replace `local-image:tagname` with the name and tag of your local image,  
    and `username/repository:tagname` with the Docker Hub repository, you want to push to.  
      
    **<mark>docker tag react_django_demo_app ketangharateg/react_django_app</mark>**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684292017721/1c02c6ce-78cc-430d-8aaa-91528153c21f.png align="center")
    
12. **Push the Image** to the Docker Hub  
    **Syntax:**  
    `docker push [OPTIONS] NAME[:TAG]`  
    `docker push username/repository:tagname`  
    Replace `username/repository:tagname` with the same repository and tag you used in the previous step.  
      
    **<mark>docker push ketangharateg/react_django_app</mark>**
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684292372109/76faff32-e132-4efb-8ddd-8798cef9ddc4.png align="center")
    
13. You will now see the Docker Image in your Docker Hub
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684292606746/a80a7153-85cb-4956-b9c1-b949bdf793fc.png align="center")
    
      
    
    Also Refer: [https://www.baeldung.com/ops/docker-compose](https://www.baeldung.com/ops/docker-compose)
    
    **Note:**  
    **<mark>DockerFile</mark>** is used to create **<mark>Images</mark>**  
    And  
    **<mark>Image </mark>** is used to create **<mark>Container</mark>**
    
    And  
    **<mark>Apps/Applications</mark>** will be running under the **<mark>Container</mark>**
