Day 13 - Docker Advanced
Project: node-todo-cicd
mkdir node-app
git clone https://github.com/LondheShubham153/node-todo-cicd.git
vim Dockerfile
# Base Image with Node js
FROM node:12.2.0-alpine
# Working directory with all the code files
WORKDIR /app
# Copy code form src to dest
COPY . .
# Install the packages
RUN npm install
# Application is ready
# Run the container with arguments
CMD ["node","app.js"]
docker build -t node-app .
docker run -d -p 8000:8000 node-app:latest
EC2-instance port 8000 should be allowed.
Search on Browser "EC2 instance Public IP-52.90.225.241:8000" It will be Run.
Docker Push
"Docker push" is a command used to upload Docker images from your local machine to a container registry, making them accessible for deployment on other systems or by other users.
docker images
docker login
docker tag java-app:latest mayurbarange/java-app:latest
docker images
docker push mayurbarange/java-app:latest
docker system prune
--> To remove unused resources like stopped containers, dangling images, and networks to free up disk space and clean up the Docker environment.docker images
docker rmi db6dd1638e3e
Docker Pull/Run
"Docker pull" is a command used to download Docker images from a registry(Docker Hub) to the local machine, making them available for creating containers.
docker run mayurbarange/java-app:latest
Docker Volume
"Docker Volume" is a feature used to persist and manage data separately from containers, ensuring data durability and enabling sharing of data between containers or with the host machine.
Project: django-todo-cicd
cd projects/
git clone https://github.com/LondheShubham153/django-todo-cicd.git
cd django-todo-cicd/
docker build -t django-todo-app .
Intermediate Layer
"Intermediate layers" in a Dockerfile represent individual steps or instructions, forming the incremental stages used during image creation before being combined into the final image layer.
docker build -t django-todo-app .
vim dockerfile
--> Let's say I have changed line number 4 in Dockerfile.
docker build -t django-todo-app .
docker run -d -p 8000:8000 django-todo-app:latest
EC2-instance port 8000 should be allowed.
Search on Browser "EC2 instance Public IP-54.225.24.13:8000" It will be Run.
How to change or rename docker image name?
docker images
docker tag django-todo-app:latest django-todo-app1:latest
docker images
docker run -d -p 8000:8000 django-todo-app:latest
How to create Docker volume?
mkdir volumes
cd volumes/
mkdir django-app
cd django-app/
pwd
/home/ubuntu/projects/volumes/django-app
cd ..
cd ..
cd django-todo-cicd/
docker volume create --name django-todo-volume --opt type=none
--opt device=/home/ubuntu/projects/volumes/django-app --opt o=bind
--> [opt-options]docker volume ls
docker run -d -p 8000:8000 --mount source=django-todo-volume,target=/data django-todo-app:latest
--> This command runs a Docker container (-d) based on the image "django-todo-app:latest," connecting the container's "/data" directory to the previously created volume "django-todo-volume," and maps the container's port 8000 to the host's port 8000 (-p).cd ..
cd volumes/
cd django-app/
ls
- Added "docker Hackathon, Docker compose, Docker multi-stage, Mayur Barange" into the public IP-54.145.97.90:8000
docker ps
docker kill 68a33aca9507
docker rm 68a33aca9507
docker run -d -p 8000:8000 --mount source=django-todo-volume,target=/data django-todo-app:latest
- Search on Browser "EC2 instance Public IP-54.154.97.90:8000" It will be Run.
- After killing container and running container, whatever I have entered data remains there stored.
Subscribe to my newsletter
Read articles from Mayur Barange directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mayur Barange
Mayur Barange
As a DevOps maestro, I orchestrate the seamless synergy between development and operations, crafting a symphony of efficiency in the digital realm. Armed with a toolkit that includes Jenkins, Git, and Docker, I navigate the continuous integration and deployment landscape with finesse. From code inception to its triumphant deployment on production servers, I am the architect of a well-automated and smoothly-scaled software lifecycle. With a passion for containerization and configuration management, I transform challenges into opportunities, ensuring that every line of code finds its perfect performance note. In the world of DevOps, I am the conductor, harmonizing innovation and reliability to create a technological masterpiece. ๐โจ