1.1 Installing Docker (Win10 professional edition)
Download address Install Docker Desktop on Windows | Docker Documentation
Note: Hyper-V must be on.
Stomp pit: When Docker is opened after installation, the connection fails, indicating that WSL is not installed (forget screenshot)
Solution: reference links in Windows installed on 10 WSL | Microsoft Docs
1.2. Configure the mirror accelerator
To improve the speed of image extraction, it is recommended to configure the image accelerator
As shown in the figure:
You can run the docker info command to check whether the configuration is successful
2. The CentOS installation
Procedure (CentOS)
1. Install the Docker
$ sudo yum install -y yum-utils
#Replace the domestic mirror source
$sudo yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
#Install the Docker
$ sudo yum install docker-ce docker-ce-cli containerd.io
Copy the code
2. Start the nginx container
#Pull the latest Nginx image
$ docker pull nginx
#Start the nginx container
#-p Specifies the port mapping. Port 2333 of the server is mapped to port 80 of the container
#-d Background running container
$ docker run -p 2333:80 -d nginx:latest
Copy the code
When pulling the Docker image, it generally goes to the official Docker source to pull the image by default. In order to optimize the speed, we replace the source of Ali Cloud image warehouse to accelerate the image download.
Add content to /etc/docker-daemon. json
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://lgt83q7k.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Copy the code
3. Pull the Nginx image
Use the docker pull command
Note: Nginx defaults to “latest” without a specific tag
4. Start the image
4.1 You can first view all images using the command docker images
4.2 Starting the Docker Run Image
Note: -p port mapping
-d The container runs in the background
-it Runs the container in interactive terminal mode
4.3 The browser can be successfully startedhttp://localhost:8080 to see the default nginx welcome page
5. Access port 80 and return to the Hello World page
5.1 Solution 1: Directly Enter the container and modify the parameters
5.1.1 Use the docker ps command to view the container that is currently running
5.1.2 in interactive terminal way into the container, you can see the default welcome page in the path ‘/ usr/share/nginx/HTML/index. The HTML”
5.1.3 Edit the file directly through Vim or run the echo command
The box ‘< h1 > Hello, Docker! < / h1 > ‘covered’/usr/share/nginx/HTML/index. The HTML ‘content.
5.2 Solution 2: Creating an Image (recommended)
5.2.1 Create a directory newnginx to store two files
5.2.2 The content of the dockerfile file is
Based on the original nginx image, add one more layer to add the local index.html file to the specified path, overwriting it if it exists
Note: You can also change the ADD statement to RUN echo ‘.
Hello, Docker!
5.2.3 Packaging an Image
Go to the directory newnginx and run docker build -t newnginx.
5.2.4 Checking whether an Image is packed Successfully
5.2.5 Starting a Mirror
5.2.6 Browser Access
Success!
FROM: Chu en, into the boat, read songs