All About Docker and Containers!

Prerequisite -
Before jumping to the article, create a personal docker hub account because it will be needed in later sections.
Install Docker in WSL (Windows Subsystem for Linux) Ubuntu.
Docker Desktop.
Topics covered in this section are listed below ->

Containers
A Docker container is a lightweight, portable, and isolated environment used to run applications. It packages your app along with all its dependencies, so it runs the same everywhere — on your laptop, a server, or in the cloud.

Example to understand Containers - > Imagine two developers working on the same Java project. One is using JDK 8, and the other is on JDK 11. When the first developer shares the source code, the second developer runs into issues — the code fails to compile and run due to missing libraries and version mismatches. This is where containers come in. By packaging the source code along with all its required libraries, dependencies, and the correct JDK version, containers ensure that the application runs consistently across any environment — regardless of what’s installed on the host system.

What is Docker?
Docker is an open-source platform that is used to deploy and run applications using containers, Docker helps you isolate your applications which can be run in any environment.
Containers vs Virtual Machines

Docker Commands
verify the version of the docker installed
docker version

list all the docker images
docker images
list all the running containers
docker ps
log in to the docker hub
docker login
pull image from Docker hub
docker pull httpd // syntax : docker pull image_name
run containers in background
sudo docker run -d httpd
stop running container
docker stop container_id
list all exited Containers
docker container ls -a
tag a specific image
sudo docker tag image_name docker_hub_username/image_name:tag -> docker nginx sayam1007/nginx:10
Push Image to docker hub
Tag the image first -> docker tag nginx sayam1007/nginx:10 then push it -> docker push sayam1007/nginx:10

Remove any image
docker rmi -f image_name -> docker rmi -f httpd
Running containers to a specific port ->
to run a container at a specific port -p flag is used.
docker run -d -p 80:80 nginx


Building Docker image and Pushing to Docker hub
Create a source code that you want to containerize.
shell script code that prints hello world


-> script.sh #!/bin/bash echo "Hello world"-> Dockerfile FROM bash COPY script.sh / RUN chmod +x script.sh CMD ["bash","/script.sh"]
After Creating Docker file and bash script , lets build the image

docker build -t image_name_you_want_to_give .
docker build -t bash .






