#Docker

What is virtual machine?
Working for virtual machine

Virtual Machine.png

Hypervisor
Types of hypervisor

Hypervisor Types.png

Docker
Docker Works

Docker Working Principle.png

Docker Vs VM.png

Docker Terminology
Docker Image
Docker Container
Docker Registry
Docker Doemon
Docker Architecture

Docker Architecture.png

Docker Image.png

Docker Container.png

Docker File Creation Basic Structure of file creation. Example: Using java
# 1. Set the base image to platform
FROM openjdk:17-alpine

# 2. Labeling (Option)
LABEL Key:Value

# 3. Create a Working Directory
WORKDIR /app

# 4. Copy the src or java files
COPY HelloWorld.java /app

# 5. Compile the java file
RUN javac HelloWorld.java

# 6. Expose the port (Option or Web Application Only)
EXPOSE 5000

# 7. Set the entry point to run the compiled Java program
ENTRYPOINT ["java", "HelloWorld"]

Explanation:

  1. Base Image: openjdk:17-alpine is a lightweight Docker image that includes OpenJDK 17.
  2. Working Directory: The WORKDIR command sets /hello as the working directory inside the container.
  3. Copy: The COPY command copies HelloWorld.java from your local system into the /hello directory in the container.
  4. Compile: The RUN command compiles the Java file inside the container.
  5. Entrypoint: The ENTRYPOINT command specifies the command to run the compiled Java program (HelloWorld) when the container starts.
Command Executed At Purpose Can Be Overridden?
RUN Image build time Executes commands to build the image (e.g., install software) No, part of the image build process
ENTRYPOINT Container start time Defines the main application or process to run when the container starts No (unless explicitly overridden using --entrypoint)
CMD Container start time Provides default arguments or command for the container Yes (can be overridden in docker run)
Best Practices:

Docker Ignore

The .dockerignore file is used to specify which files and directories should be excluded when building a Docker image. It works similarly to a .gitignore file in Git. By specifying patterns in .dockerignore, you can prevent unnecessary files from being copied into the Docker image, helping reduce the image size and build time.

Why Use .dockerignore:

Example of a .dockerignore File:

# Ignore node_modules directory
node_modules

# Ignore logs and temp files
*.log
tmp/

# Ignore any .env file (contains sensitive data)
.env

# Ignore Git-related files
.git
.gitignore