• The code for this document: github.com/LiangJunron…
  • Docker series: github.com/LiangJunron…

After the above operation, after the installation, we start to toss it:

  • Deploy an Nginx service on Docker with a simple index.html page
  • Explain Docker Dockerfile, image, container and other concepts, and modify the image source layout in advance

So, Here we go~

One, command operation

First, we’ll create a new folder for Demo-01, and then the console will type:

  • Jump to this folder:cd demo-01

And store 2 files in it:

Dockerfile

# This image is copied from the Nginx image
FROM nginx

# Move index.html from current directory to Nginx HTML directory
COPY ./index.html /usr/share/nginx/html/index.html

# Expose port 80 of the mirror
EXPOSE 80
Copy the code

index.html

<! DOCTYPEhtml>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="Width = device - width, initial - scale = 1.0, the maximum - scale = 1.0, user - scalable = no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Hello Docker</title>
  <style>
    /* Set the page center to display Hello Docker! * /
    body {
      margin: 0 auto;
      width: 1000px;
    }
    h1 {
      text-align: center;
    }
  </style>
</head>
<body>
  <h1>Hello Docker!</h1>
</body>
</html>

Copy the code

We then write instructions to create an Image:

  • Docker image build./ -t docker-nginx:1.0.0

Next, we create a Container:

  • Docker container create -p 2222:80 docker-nginx:1.0.0

The console returns a string of characters, the result of creating the container

Finally, we run the Container:

  • docker container start 312b8278e11373cb3211faeab53b7f0b47e996b5e84fc58

At this point, if you open the screen: http://127.0.0.1:2222/

You’ll see:

Congratulations to you! Get Docker

If you have a local area network or WIFI, you can change your IP address (http://ip address :2222/). Under normal circumstances, you can access successfully.

Second, the summary

So, after this series of operations, start Nginx service, so some of the contents: Dockerfile, image, container, etc.

So, we have a few concepts to understand:

  • What is a Dockerfile?
  • What is an Image?
  • What is a Container, “Container”?

Below we will go through all of them and list the instructions that beginners like Jsliang should know when getting started.

What is a Dockerfile?

A Dockerfile is a text file used to build an image. The text content contains the instructions and instructions required to build the image.

Docker automatically generates images by reading instructions in a Dockerfile.

Dockerfile can be used to invoke any command on the command line.

Dockerfile is generally divided into four parts: basic image information, maintainer information, image operation instructions and container startup instructions.

In a nutshell: You can use a Dockerfile to tell Docker what to look for when compiling, just as you can use package.json to tell NPM what packages I need to install.

Reference: Huawei Cloud – What is Dockerfile

What is an Image?

An image is a file system that provides the files and parameter configurations needed to run the container.

It is equivalent to the installation package you need to download to use a software and the ISO file you need to install an operating system.

To put it simply: you can think of the Image as a Windows 11 cd-rom, and then any computer that needs a new operating system can be installed based on that CD-ROM.

There are many images on Docker Hub, interested partners can go to view and download: hub.docker.com/

It is worth mentioning that:

  • The download speed of domestic official sources will be slow, so it is a good choice to switch to a domestic source address like NPM, such as University of Science and Technology of China (USTC), Ali Cloud, NetEase, Docker official China area, etc
Name of the Mirror warehouse link
Docker official China section registry.docker-cn.com
Netease 163 hub-mirror.c.163.com
University of Science and Technology of China docker.mirrors.ustc.edu.cn
Ali cloud https:// < ID >. Mirror.aliyuncs.com

Mac address modification mode:

  1. Modify Docker image repository configuration:sudo vim /etc/docker/daemon.json
  2. Modifying a configuration file:

daemon.json

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],}Copy the code
  1. To make the configuration file effective:sudo systemctl daemon-reload
  2. Restart the Docker:sudo service docker restart

Windows Modification mode:

Docker info:

Of course, it is important to note that when the source switch is restarted, it will cause the current container to pause and restart again.

References: Zhihu – Test of energy – Docker Primer: Image image

What is a Container?

A Container is a lightweight virtualization technology that, like VMS, creates an isolated environment.

The relationship between an Image and a Container is similar to that between classes and instances in programming, where an Image is a static definition and a Container is an entity of the Image runtime.

Combining our previous small example, we see:

  • Create an Image:Docker image build./ -t hello-docker:1.0.0
  • Create a Container:Docker container create -p 2222:80 Hello-docker :1.0.0

In this case, we create a container with hello-docker:1.0.0 as the image’s REPOSITORY and TAG. We create a container based on this image and specify its port.

Also, when talking about ports, we talked about the host, which is the host as opposed to the container, which is Windows 10 for Jsliang’s laptop.

On the point! There will be a host in the back, don’t miss the point!

Six, the summary

With that in mind, it’s time to go back and review!

So in the next chapter, we’ll talk about that; 04 – Getting started & Node Services

Stay tuned!


Do not toss the front end, and what is the difference between salted fish!

Thumbs up/Star if you think the article is good.

If you need to contact jsliang:

  • Github

Personal contact information stored in Github home page, welcome to toss ~

Build yourself into a lifelong learning programmer who is eager to explore, play around, and expand your knowledge.

Jsliang’s document library is licensed by Junrong Liang under the Creative Commons Attribution – Non-commercial – Share alike 4.0 International License. Based on the github.com/LiangJunron… On the creation of works. Outside of this license agreement authorized access can be from creativecommons.org/licenses/by… Obtained.