Docker Introduction in Azure

Subham Pradhan
6 min readFeb 29, 2024

--

Docker: Advanced Version of Virtualization.

Why Docker?

  1. Proper utilization of resources.
  2. Resolves dependencies issues in environment variables.

Advantages of Docker over Virtual Machine:

  1. Lightweight
  2. Occupies less space
  3. Easily portable with a short boot-up time
  4. Applications run in isolation, allowing different apps on a single OS
  5. Portability — Runs on any machine
  6. Isolation — Containers are isolated from each other
  7. Reproducibility — Images can easily be accessed and reused
  8. Resource Efficiency — Containers share the host machine’s kernel, improving performance.

Docker Image: A lightweight, standalone, and executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, and system tools.

Docker Container: An instance of a Docker image that runs a software application, encapsulated with its dependencies and isolated from the host system.

Docker Hub : Docker Hub is a public registry where user/developers can store and share system images created by them and making them to easily access and reuse images for other software developers.

Docker Logs: Docker daemon and Docker containers will generate the docker logs in the form of text messages which will helps you in further to troubleshoot problems, monitor the performance of your applications, and gather information about the state of your Docker environment.

Docker Build: Docker build is an command which is used to build the docker image by using the Docker file.

Docker Ubuntu: Docker Ubuntu is the term used for utilizing the Docker service with Ubuntu-based operating systems. Running Docker is best suited for the popular Linux distribution Ubuntu.

# Create a Resourse Group :
# Launch a virtual machine - 
Take Ubuntu Image - Name: Docker-Host
# Connect the virtual Machine :
# Launch an EC2 instance with Ubuntu as the operating system and install Docker on it.
sudo su
cd
apt update && apt install docker.io
docker --version
systemctl start docker
systemctl enable docker # Now, the EC2 instance will be configured as a Docker Host
docker container ls # No container will show
docker image ls # Running images will be displayed
docker container ls -a # All running, stopped, and exited containers will be shown
docker container run ubuntu # Install an Ubuntu image from Docker Hub if not available locally (start->stop)
docker image ls
docker container ls -a
# Block the terminal for 60 seconds (automatically release after):
docker container run ubuntu sleep 60
# Turn off terminal block but in running state:
docker container run -d ubuntu sleep 60
docker container ls
# Configuring Inside Docker Container:
---------------------------------------
docker container run -it ubuntu /bin/bash
apt-get update
apt-get install apache2
cd /var/www/html/
echo "This is a test" > index.html
cat index.html
service apache2 start
# Will not stop until we trigger the stopping command (d-detach mode, it-interactive mode):
docker container run -d -it ubuntu
# If you want to stop and start:
docker container stop <container-id> # Stop the container
docker container ls # Remove from the running state
docker container ls -a # Will see exited status
docker container start <container-id> # Start the container again
# Deleting All Docker Containers:
docker container rm 3a2 8b6 9h3 # Remove containers in running state with force
# To remove all Docker containers forcefully:
--------------------------------------------
docker container rm 3a2 8b6 9h3 -f
# Port Mapping: Map a port from the Docker container to the Docker host
docker container run -it -p 3600:80 ubuntu /bin/bash # Port 3600 on Docker host mapped to port 80 on Ubuntu container
apt-get update
apt-get install apache2
cd /var/www/html/
echo "from container b65" > index.html
ls
cat index.html
service apache2 start
# Running Multiple Applications: (1 server: many applications will run) 
# Run multiple applications on the same Docker host using different port mappings and containers.
docker container run -it -p 3700:80 ubuntu /bin/bash
apt-get update
apt-get install apache2
cd /var/www/html/
echo "from container xyz" > index.html
ls
cat index.html
service apache2 start
# Access the content from the Docker host's public-IP:3600
docker container stats # Will see the status of all containers
# Port
# Access the content from the Docker host's public-IP:3600
Add inbound Security for destination port 3600
# Use ctrl+p+q to exit or detach from the Docker container
# To inspect details about Docker Container:
docker container inspect <container-id>
# (Copy the private-IP address from the inspect output and use it to access the content.)
curl private-IP # Will show - "This is a test"

# For publicly accessible, port mapping is needed
# Exit or Out of the Docker container:
ctrl + p + q
# Go inside of the container
docker exec -it e53 /bin/bash

--

--

Subham Pradhan

DevOps Engineer | CI/CD | K8S | Docker | Jenkins | Ansible | Git | Terraform | ArgoCD |Helm|Prometheus|Grafana|SonarQube|Trivy|Data Engineer | Azure |DevSecOps|