Docker - Project

GitHub:
https://github.com/LondheShubham153/node-todo-cicd.git 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
    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","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 -> Instances -> Security -> Security groups > Inbound rules > Edit inbound rules > Add rule > for TCP Port 8001 - from 0.0.0.0/0

  7. Browser the Application on the browser

  8. Check the Docker logs
    docker ps
    docker logs <Container ID>

  9. You can push the image to your Docker Hub Repo.
    Docker Hub: 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

  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.

    docker tag react_django_demo_app ketangharateg/react_django_app

  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.

    docker push ketangharateg/react_django_app

  13. You will now see the Docker Image in your Docker Hub

Also Refer: https://www.baeldung.com/ops/docker-compose

Note:
DockerFile is used to create Images
And
Image is used to create Container

And
Apps/Applications will be running under the Container