- It is an open source container Runtime
- Command Line tool
- Dockerfile file format for building container images
- docker pull (service_name)
- docker run (service_name)
- docker ps { List of Running Containers }
- docker run -d (service_name) {Starts New Container with Detached Mode}
- docker stop (container_id)
- docker start (container_id)
- docker ps -a {Lists running and stopped containers}
- docker run -p host_port:from_port
- docker logs (container_id)
- docker run -d -p 6001:6373 --name (any_name) (service_name)
- docker exec -it (container_id) /bin/bash
- docker images
- docker network ls
- docker network create (network_name)
- docker run -p (port):(port) -d -e (environment_var) --name (custom_name) --net (network_name) (service_name)
- docker compose build {build the images}
- docker compose start {starts the containers}
- docker compose stop {stops the containers}
- docker compose up -d {Build and start }
- docker compose ps {Lists what is running}
- docker compose rm {Remove from the Memory}
- docker compose logs
- docker compose exec (container) bash
- docker compose --project-name test1 up -d {run the instance as a project}
- docker compose -p test1 up -d {shortcut}
- docker compose ls {Lists running projects}
- docker compose logs -f (service_name)
- docker build -t (image_name):(tag) (docker_file location)
- docker rm (container_name)
- docker rmi (image_name)
- docker info {Display System Information}
- docker version
- docker login {Login to docker registry }
- docker image inspect (image_name)
- docker run --memory="256m" (image_name) {Set Max Memory}
- docker run --cpus=".5" (image_name) {Set Max CPU'S}
- docker create volume (volume_name) {Create New Volumes}
- docker volume ls {List of Volumes}
- docker volume inspect (volume_name) {Display Volume info}
- docker volume rm (volume_name)
- docker volume prune {Delete all unmounted volumes}
- docker run -d --name test -v myvolue:/app (image_name) {/app is logical address in container}
- A way to package application with all the necessary dependencies and configuration
- Portable artifact, easily shared and moved around
- Makes development and deployment process easier
- Each Container have there own isolated environment and packaged with all needed configuration
- Container contain all necessary things to run code , Runtime , System Tools , System Library
- Container are ephemerous and stateless
- We don't generally store data in Containers
- So When Container Destroyed then Data inside them as well
- To Store Data We Should Store data outside the container also called as Volume
- Volumes Map is mapped to logical folder (maps a folder on host to logical Folder in Containers)
- Move fast by deploying small units
- use few Resources
- Fit more in same host
- Fast Automation
- Portability
- Isolation
Container is
- Layers of Images
- Bottom most is mostly linux based image because of small in size (alpine)
- Application image on top
- Docker image is the actual package
- Any System can be divided into 3 Section
- Application
- Os Kernel
- Hardware
- OS manages Application and OS Kernel
- Docker virtualize Application Layer and Use Kernel of Host
- Virtual Machine Virtualize Application and OS Kernel Both Which is Heavy Task
- Container is running environment for IMAGE
- Image is a read-only template that contains the necessary files and dependencies to run a piece of software.
- Container is an instance of an image that can be run and executed on a host machine.
- Containers are lightweight and share the host machine's operating system kernel, making them more efficient than virtual machines.
- Container provide File System, Environment Configs , Application Image
- Container has port binded to it which make it possible to application running inside the container to talk
- Multiple Containers can run on your host machine
- Host Have limited Number of port available
- if the container demanding port is already taken then we use by other container then another open port of host machine is used
- service in same container can talk to each other without using localhost
version: '3' (version of docker-compose)
services:
mongodb: (new_container_name)
image: (image_name)
ports:
- (port_host):(port_container)
environment:
- Mongo_UserName=admin - Docker composer take care of creating the a common network
- Data present in docker get remove when we restart the docker container
- Define and run multi-container applications
- Define using YAML files
- Use For WorkLoads that don't required a full orchestrator
- Development and testing
version: '3.8' # Specify the version of docker-compose
services:
mongodb:
image: mongo:latest # Use the latest MongoDB image
container_name: mongodb_container
ports:
- "27017:27017" # Map port 27017 on the host to port 27017 in the container
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
networks:
- my_network # Connect to the custom network
nodeapp:
image: node:latest # Use the latest Node.js image
container_name: nodeapp_container
ports:
- "3000:3000" # Map port 3000 on the host to port 3000 in the container
depends_on:
- mongodb # Ensure MongoDB starts before this service
networks:
- my_network # Connect to the custom network
networks:
my_network:
driver: bridge # Use the default bridge driver- We use depends_on to Make sure that it run after dependency is full filled
- we can define reservation of Resources and limits of Resources as well
- We can Access the Environment Variable using ${ENV_VAR}
- Blueprint for creating docker image
FROM node (install node)
ENV MONGO_DB_USERNAME = admin \
MONGO_DB_PWD = password
RUN mkdir -p /home/app (RUN can run any linux command)
COPY . /home/app (EXECUTE ON HOST it copy from host to image)
CMD ["node", "server.js"] (act as entry point)
- Build as single unit
- Deployed as single unit
- For scaling Duplicate on each server
- A variant of service-oriented architecture (SOA) structural style
- arranges an application as collection of loosely coupled services
- In microservice architecture , services are fine-grained and the protocol are light weight
- Segregates functionality into smaller separated services each with a single responsibility
- scale out by deploying each service independently
- Each Services are loosely coupled
- Enables autonomous development by different teams , languages and platforms
- CI/CD: continuous Integration and Deployment
- improved fault isolation
- Eliminate vendor or technology Lock in
- Ease to understand
- smaller and faster to deploy
- Complexity is added to resolve issues
- One update in microservice may impact other microservices
- Manage multiple database
- Latency Issues
- Transient Error
- Multiple Point of Failure
- Security Issues
- Its an new way of thinking about building complex system
- widely popular in open source communities
- Cloud native foundation empowers organization to build and run scalable application in modern and dynamic environment such as public , private and hybrid clouds
- Cloud native refers to software applications, technologies, and architectures designed from the ground up to optimize the use of cloud computing characteristics, such as scalability, resilience, and automation. These systems leverage cloud-native technologies like containers, microservices, serverless functions, and immutable infrastructure to build and deploy scalable, flexible, and resilient applications that can be easily managed and monitored.
- Kubernetes pattern
- Microservices pattern
- Domain Driven Design
- Clean Code
- infrastructure become immutable and disposal
- Containerization
- CI/CD: Continuous Integration / Continuous Delivery
- Orchestration and application definition
- Analysis
- Service Proxy, Discovery and Mesh
- Networking and Security Policies
- YAML aren't markup language
- Human friendly data Serialization Standard
- Used by docker compose and kubernetes