Powered by Blogger.

DevOps Docker Fundamentals - Part 1

No comments :

DevOps - Docker Tutorial - Part 1

Understand Docker fundamentals and Java REST API flow through diagrams and examples.

By A143MK  |  DevOps Learning Series  |  Beginner

1What Is Docker?

Docker helps you package an application and the files it needs into an image. You can use that image to start an isolated process called a container. This makes setup and delivery more repeatable across development and deployment environments.

Unlike a traditional virtual machine, a Linux container shares the host's Linux kernel instead of running a separate guest operating system. On Windows, Docker Desktop runs Linux containers using a Linux environment.

In this lesson: Explore Docker images, containers, port mapping, and Java REST API flow using diagrams.

2Key Docker Concepts

  • Dockerfile: A text file containing instructions for building an image.
  • Image: A packaged template containing your application and its runtime files.
  • Container: An instance created from an image; a running container executes its configured process.
  • Registry: A service that stores images. Docker can download public images from Docker Hub.
  • Port mapping: A connection between a port on your computer and a port in the container.
DockerfileBuild instructions
ImagePackaged template
ContainerRunning instance
Remember: Building creates an image; running creates and starts a container from that image.

3Prerequisites and Setup

  1. Install and start Docker Desktop for Windows. Follow Docker's current Windows and WSL 2 requirements.
  2. Use Linux containers, open PowerShell, and check that Docker Desktop is running.
  3. The optional Nginx command later needs internet and a free local port 8080; installation is not needed just to read this article.
docker --version
docker info

docker --version prints the CLI version. docker info should also show server information. If it cannot connect to the engine, start Docker Desktop and try again.

Safety: This is a local learning example, not a production deployment. Never put passwords or other secrets in an image or its build context.

4Docker Architecture

The Docker client sends your commands to the Docker engine. The engine manages images, containers, and networks, and downloads images from a registry when needed.

Docker CLISends commands
Docker EngineManages containers
RegistryStores images
Example: Docker Hub is a registry. Docker Desktop includes the client, engine, and other tools.

5Image Lifecycle

An image is built from Dockerfile instructions and a build context. It can be tagged, pushed to a registry, and used to create multiple containers.

BuildCreate image
RegistryShare image
RunStart container

Rebuilding an image does not change an existing container. Create a new container to use the new version. Use separate storage such as a volume for persistent data.

6Port Mapping Diagram

Port mapping connects a port on your computer to a port in the container. Below, the web server listens on port 80 inside the container.

Browserlocalhost:8080
Host port127.0.0.1:8080
NginxContainer port 80

This optional command starts a container from the public Nginx image. It needs internet to download the image; press Ctrl+C to stop it. --rm removes the container after it stops.

docker run --rm --name a143mk-nginx -p 127.0.0.1:8080:80 nginx:alpine
Binding to 127.0.0.1 limits access to your computer. If 8080 is busy, map another free host port to port 80.

7Common Docker Commands

Use these commands to inspect images and containers:

docker image ls
docker ps
docker ps -a
  • docker image ls lists local images.
  • docker ps lists running containers; docker ps -a also includes stopped containers.
  • docker logs a143mk-nginx shows logs while the example container exists.

8Docker Tools and Their Uses

These tools help you build, share, and inspect containers. Here are their key features and how they fit into later lessons.

Docker Desktop

Features: Provides a local Docker engine, CLI, and graphical dashboard for viewing images, containers, and logs.

Later use: Run and troubleshoot containers locally during development.

Docker CLI

Features: Manage Docker using commands such as docker build, docker run, and docker logs.

Later use: Automate builds and checks in terminals and CI/CD pipelines.

Docker Hub

Features: An image registry for sharing images through public or private repositories.

Later use: Publish images built in CI and pull them for deployment.

Docker Compose

Features: Define and manage multiple services, networks, and volumes together with YAML configuration.

Later use: Run a Java API and database together for local development.

Docker Buildx

Features: Offers advanced BuildKit-based builds, including multi-platform images.

Later use: Build images for different CPU architectures in CI with an appropriate builder setup.

Docker Scout

Features: Helps analyze image packages for known vulnerabilities and review remediation options.

Later use: Review image risks before delivery; scanning does not guarantee security.

Note: Availability, installation, sign-in, and plan requirements vary by tool and environment. See the official links for details.

9Java REST API Flow

Imagine a Java REST API running inside a Docker container. A client sends an HTTP request and the API returns a JSON response.

ClientGET /api/hello
DockerJava API container
Response200 OK · JSON

Java code illustration

@RestController maps a Java class to HTTP endpoints. This is an illustration of a Spring Boot controller; running it requires a Spring Boot application and its dependencies.

import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
class HelloController {
    @GetMapping("/api/hello")
    public Map<String, String> hello() {
        return Map.of("message", "Hello from Java!");
    }
}

Interactive illustration: Press the button to see an example response. This is a browser simulation; no real API request is sent.

10Troubleshooting

  • Docker command not found: Confirm Docker Desktop is installed; reopen PowerShell and check the installation instructions.
  • Cannot connect to the Docker engine: Start Docker Desktop and wait for it to be ready, then retry docker info.
  • Port 8080 is already in use: Choose another unused port, such as 127.0.0.1:8081:80, and visit http://localhost:8081.
  • Container name already exists: Inspect it with docker ps -a and choose a different name for the example.
  • Container exits or the page fails to load: While the container exists, check docker logs a143mk-nginx for errors. With --rm, it is removed when it stops.

11Quick Quiz

Choose an answer for each question and check your results.

1. What does docker build create?
2. Which command starts a container from an image?
3. Which port does the sample Nginx server use inside the container?

12What Comes Next?

You have explored Docker images, containers, port mapping, and Java API flow. Next, learn how Kubernetes manages containerized applications and how CI/CD automates building and delivering them.

Continue learning with the official Docker getting-started guide.

A143MK Blogs  |  DevOps Learning Series  |  Docker Tutorial Part 1

No comments :

Post a Comment

Please Write a Message for Programming or something else 🙏