Copy the django-todo-cicd code from the repository.
Click on code tab and clone the code from Git Hub to your local machine.
With Git clone command we have cloned the code to the local machine in the Projects directory.
Once we pull the code from the repo by default the docker file is there with that code so no need to create it again. Please see below the content of the docker file.
Post that we have to build the docker image with docker build command.
We checked and confirmed that django-todo-app image is available
Then, we run the django-todo-app through "docker run" command
The Important step is to check whether port 8000 is open from the EC2 instance .. Check in the security group from inbound rules the port is in active state.
& access the application through the browser with port 8080.
We can add multiple tasks from the tab add , but if we can kill or stop the containers with docker kill command then all the data has gone & it would be a risk if we are in the production environment. I was added do studies and Hello How are you all.
If we create an app with again docker run command and check that app through the browser all data has vanished.
So the solution to avoid this is to create a docker volume. Volumes play a crucial role in managing data in Dockerized applications, providing a solution for scenarios where data persistence and sharing are necessary.
We can use the docker volume ls command to check the available volume on the system.
By default, docker uses local volumes
So from here, we can start to create a volume.
IMP Note: We should come outside from django-todo-cicd repo, cause we don't create a volume within a repository. So we will go inside the project directory & create a volume directory there & within the volume directory , we can create a directory called django-app
Below is the path of my volume /…once we create a volume we can give the below path. (Path should be given to your local device)
Then we can create a volume with docker volume create command:
Then we have to attach the volume with the command docker run -d -p 8000:8000 --mount source=django-todo-volume,target=/data django-totodo-app:latest
& then run the application through a browser.
After this, we have to kill the container with docker kill command and remove the image with docker rm command.
Again we have to run the command "docker run -d -p 8000:8000 --mount source=django-todo-volume,target=/data django-totodo-app:latest"
We have checked through the app again through the browser and Hurray, the data did not vanish…All data is persist there Please see the below screenshot.
Happy Learning!!