Below is your content converted into a clean, well-structured Markdown (.md) document with a short analysis section at the beginning (as you requested). I also fixed spelling, formatting, headings, and diagrams so it renders nicely in GitHub, Notion, or any Markdown viewer.
You can save it as: docker-notes.md
# Docker Notes
## Analysis
Docker is a containerization platform that solves software compatibility issues across different environments. Instead of installing software stacks (Java, Node, Angular, etc.) separately on every server, Docker packages the application along with its dependencies into an image. This image can then run consistently on any system that has Docker installed.
Key benefits include:
- Eliminates compatibility issues
- Simplifies deployment across multiple servers
- Enables faster software upgrades
- Ensures consistent environments from development to production
---
# Docker
## Why Docker?
- Resolves **compatibility problems** using containerization.
- Helps install software on different servers **without worrying about dependency conflicts**.
- Allows deploying the **same application on multiple servers for load balancing** without manually installing the technology stack.
- Enables **easy software upgrades across multiple machines**.
---
## Important Notes
✔ **Docker Engine** acts as a bridge between the container and the host OS.
✔ Containers **do not have their own kernel**; they use the **host's kernel**.
✔ Docker Engine **manages containers but does not create them** — it runs and controls them.
---
## Basic Architecture Flow
Linux VM
↓
Install Docker Engine
↓
Docker Engine acts as bridge between Linux Kernel and Docker Containers
↓
Provides isolated environment to run Docker Images
Docker Container
Docker Engine
Linux VM
---
# Docker Architecture
## Components
### Dockerfile
Contains instructions to build a Docker image.
### Docker Image
Application package including:
- Application code
- Dependencies
- Libraries
- Runtime environment
### Docker Registry
Repository to store Docker images.
Examples:
- Docker Hub
- Private registries
### Docker Container
An isolated environment where a Docker image runs.
---
# What is Containerization?
Containers package an application **along with its dependencies** (libraries, configuration files, etc.) ensuring it runs consistently across different computing environments.
plaintext
Dockerfile
↓
Docker Image
↓
Docker Registry / Docker Hub
↓
Docker Container
Example flow:
plaintext
Dockerfile
(Contains instructions
to download dependencies)
↓
Docker Image
(Application + Dependencies)
↓
Docker Hub / Registry
(Collection of images)
↓
Containers
(Container1, Container2)
Running inside:
plaintext
Linux Server
---
# Installing Docker
## Install Docker on Amazon Linux
```
bash
sudo yum update -y
sudo yum install docker -y
sudo service docker start
sudo usermod -aG docker ec2-user
exit
Install Docker on Ubuntu
bash
sudo apt update
curl -fsSL get.docker.com | /bin/bash
sudo usermod -aG docker ubuntu
exit
Verify Docker Installation
bash
docker -v
Pull Sample Images
Practice pulling images from Docker Hub.
Example:
bash
docker pull psait/helloacademy:latest
Official example:
bash
docker pull hello-world
Important Docker Commands
Pull Image
Download image from Docker Hub.
bash
docker pull [image-name]
Run Container
Creates and runs a container.
bash
docker run [image-name]
List Running Containers
bash
docker ps
List All Containers
bash
docker ps -a
Stop Container
bash
docker stop [container-id]
Start Container
bash
docker start [container-id]
Remove Container
bash
docker rm [container-id]
Remove Docker Image
bash
docker rmi [image-name or image-id]
Remove Unused Containers and Images
bash
docker system prune -a
Running Container with Port Mapping
Running a container normally:
bash
docker run [image-name]
You cannot access it in a browser unless you map ports.
Port Mapping
Syntax:
bash
docker run -p host-port:container-port [image-name]
Example:
bash
docker run -p 9090:9090 [image-name]
Run container in background:
bash
docker run -d -p 9090:9090 [image-name]
Access application:
shell
http://public-ip:host-port
Important Notes
- Enable Inbound Rules in the security group for the host port.
- If running multiple containers, each must use a different host port.
Install Jenkins using Docker
bash
docker run -d -p 8080:8080 jenkins/jenkins
Enable port 8080 in the security group.
Installing Jenkins Without Docker
Step 1 — Create Linux VM
Use Ubuntu EC2 instance (t2.medium).
Enable port 8080 in security group.
Step 2 — Install Java
bash
sudo apt update
sudo apt install fontconfig openjdk-17-jre
java -version
Step 3 — Install Jenkins
bash
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
bash
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
bash
sudo apt-get update
sudo apt-get install jenkins
Step 4 — Start Jenkins
bash
sudo systemctl enable jenkins
sudo systemctl start jenkins
Step 5 — Verify Jenkins
bash
sudo systemctl status jenkins
Step 6 — Access Jenkins
shell
http://public-ip:8080
Step 7 — Get Jenkins Admin Password
bash
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Step 8 — Create Admin User and Install Plugins
Example Docker Installations
SonarQube
bash
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube:lts-community
Nexus
bash
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
Creating a Dockerfile
Dockerfile instructions are case-sensitive and must be written in uppercase.
1. FROM
Defines base image.
dockerfile
FROM openjdk:17
Examples:
docker
FROM python:3.9
FROM openjdk:17
FROM tomcat:9.0
2. MAINTAINER (Deprecated)
Old:
docker
MAINTAINER Name <email>
New:
docker
LABEL maintainer="Name <email>"
3. RUN
Executes commands during image build.
dockerfile
RUN git clone <repo-url>
RUN mvn clean package
4. CMD
Default command when container starts.
dockerfile
CMD "java -jar myapp.jar"
Only the last CMD instruction will run.
Example Dockerfile
dockerfile
FROM openjdk:17
MAINTAINER Hello
RUN echo 'run-1'
RUN echo 'run-2'
CMD echo 'cmd-1'
CMD echo 'cmd-2'
Build Docker Image
bash
docker build -t helloacademy/image1 .
. means Dockerfile is in the current directory.
List Docker Images
bash
docker images
Run Image
bash
docker run [image-id]
ENTRYPOINT
Alternative to CMD but cannot be overridden.
Example:
docker
CMD "java -jar app.jar"
Better:
docker
ENTRYPOINT ["java","-jar","app.jar"]
COPY
Copies files from host to container.
dockerfile
COPY target/app.jar /usr/app/
ADD
Similar to COPY but can extract .tar files.
dockerfile
ADD target/app.jar /usr/app/
Note:
ADD cannot download from HTTP/S3 URLs.
WORKDIR
Sets working directory.
dockerfile
WORKDIR /usr/app/
EXPOSE
Specifies application port.
dockerfile
EXPOSE 8080
Dockerizing Spring Boot Application
Spring Boot applications are packaged as JAR files.
Run command:
bash
java -jar app.jar
Default port:
plaintext
8080
Dockerfile for Spring Boot
dockerfile
FROM openjdk:17
COPY target/demo-app.jar /usr/app/
WORKDIR /usr/app/
EXPOSE 8080
ENTRYPOINT ["java","-jar","demo-app.jar"]
Steps to Build and Run
Clone Repository
bash
git clone <repo-url>
Build JAR
bash
mvn clean package
Build Docker Image
bash
docker build -t psait/helloacademy:<tag> .
Tags example:
- prod-v1
- dev-v1
- test-v1
- staging-v1
List Images
bash
docker images
Run Container
bash
docker run -d -p 8080:8080 --name psa psait/helloacademy
Check Running Containers
bash
docker ps
View Logs
bash
docker logs <container-id>
Access Application
plaintext
http://public-ip:8080
Push Image to Docker Hub
Login
bash
docker login
Enter:
plaintext
username
password
Push Image
bash
docker push psait/helloacademy:<tag>
Top comments (0)