Understanding Docker

12006

Learning Objectives

  • Deploy Docker Projects: Use the Docker plugin in the Jianghu panel to deploy Docker projects.
  • Container Management: Manage Docker containers in the Jianghu panel, including operations such as starting, stopping, and deleting.
  • Image Management: Learn how to manage Docker images in the Jianghu panel, including importing and exporting images.
  • IP Address Pool: Learn how to manage Docker's IP address pool in the Jianghu panel.
  • Repository Management: Learn how to manage Docker repositories in the Jianghu panel.

1. Installing Docker

Docker is an open-source containerization technology platform that allows developers to package applications and their runtime environments into containers. These containers are lightweight, portable, and run in their own isolated environments, ensuring consistency across different environments.

Docker addresses the issue of "it works on my machine, why doesn't it work on others?" By ensuring environmental consistency through containers, Docker simplifies the configuration process, enhances the efficiency of software deployment and delivery, and makes it suitable for modern Continuous Integration and Continuous Deployment (CI/CD) processes.

The Jianghu panel provides a "Docker" plugin, which can be installed to deploy Docker projects and manage Docker images and containers.

  1. Log in to the Jianghu panel.
  2. Click on the "Software" section on the left sidebar to enter the software management page.
  3. On the software management page, find Docker and click install.

2. Deploying Docker Projects

The Jianghu panel standardizes Docker projects, with each project having a default docker-compose file, and it is recommended to store project files in the /www/wwwroot/ directory.

  1. In the Jianghu panel, click on the "Docker" section on the left sidebar to enter the Docker management page.
  2. Click on "Project List," then click the "Create Project" button to open the new project dialog.
  3. In the new project dialog, fill in the project name and the Compose file content.
  4. Click "Submit" to create the project.
  5. Click the "Start" button in the project action column to quickly start the Docker project.

3. Managing Docker Images and Containers

Docker Image is a lightweight, executable package that contains everything needed to run an application, including code, libraries, environment variables, and configuration files. Container is a running instance of an image, executing applications in an isolated environment while maintaining environmental consistency.

In Docker, the relationship between images and containers is similar to that of blueprints and actual buildings. A Docker image is a lightweight, immutable snapshot of a file system that contains everything needed to run an application (code, libraries, environment variables, configuration files, etc.). When you start an image, it creates a container on the Docker engine. A container is a live, writable execution instance of an image, running in an isolated environment and maintaining consistency with the state defined by the image. It can be understood that an image is a static definition, while a container is the dynamic manifestation of the image at runtime.

Container Management:

  1. On the Docker management page, click on "Container List" to see the list of created containers.
  2. In the list, various operations can be performed on the containers, such as opening the container terminal, viewing logs, deleting, etc.

Image Management:

  1. On the Docker management page, click on "Image List" to see the list of acquired images.
  2. Click to acquire an image, fill in the image name and other information to pull the specified image from the repository.
  3. In the list, you can perform operations such as pulling updates and deleting images.

5. Exporting and Importing Images

Docker allows users to save modified containers as new images and export them as tar files. The benefit of this is that users can easily transfer this image to other servers and quickly start a container that is identical to the original, achieving environmental consistency and rapid deployment.

The Docker plugin in the Jianghu panel provides the functionality to export images:

  1. In the Docker plugin dialog, click "Image Export" --> "Image Packaging" button to package the specified image into a compressed file.
  2. The packaged image file will appear in the list below, where you can download, import, or delete it.
  3. Click the upload image button to upload image files packaged from other servers for import and other operations.

6. IP Address Pool

The Docker IP pool is a series of preset IP address ranges used for automatic allocation to Docker containers. This not only ensures that each container has a unique IP address for network communication and resource management but also avoids IP address conflicts, maintaining a clean and orderly network environment.

  1. In the Docker plugin dialog, click the "IP Address Pool" button to enter the IP address pool management page.
  2. On the IP address pool management page, you can view and manage Docker's IP address pool.

7. Repository Management

A Docker Repository is a place to store Docker images. It can be likened to a code repository, but it stores Docker images instead of code. Docker repositories can be public, such as Docker Hub, where anyone can download and use the images, or private, for specific users or teams.

You can log in and manage Docker repositories through the Jianghu panel Docker plugin:

  1. In the Docker plugin dialog, click the "Repository" button to enter the repository management page.
  2. On the repository management page, you can view and manage Docker's repositories. Click the login button, fill in the repository information, and click login to add the repository.
  3. In the repository management list, you can modify repository information and delete repositories.

8. Case Study: Deploying SeaTable with Docker

SeaTable is a new digital platform based on smart tables. It supports a variety of rich data types such as "files," "images," "single choice," "collaborators," and "calculation formulas," helping users organize and manage various information in tabular form.

You can try deploying a SeaTable instance using Docker. In the 304 - Advanced System Operations course, a SeaTable deployment tutorial is provided.

Many applications are deployed via Docker. The 304 - Advanced System Operations course also provides deployment tutorials for other Docker applications:

You can try deploying these projects on the server.

Assignment

  1. Based on the content of this article, deploy a Docker project named nginx with the following docker-compose content:
version: "3"
services:
  nginx:
    image: nginx:alpine
    ports:
      - 81:80
      - 444:443
    volumes:
      - ./html:/usr/share/nginx/html
  1. Add index.html under the project directory /html/ with the content "Hello World!"

  2. Open TCP port 81 on the server and access the container homepage using the following address, which should display "Hello World!":

http://x.x.x.x:81