PrefaceFirst install Docker. Use the script in the article to quickly create a CentOS 7.8 virtual system cluster and connect to it through the SSH (Secure Shell) remote tool. Create a bridge network to facilitate communication between containers The instruction format is docker network create test-network List all networks under Docker and you can see test-network. docker network ls Creating a container from a CentOS 7 image Run To create multiple containers on the same host, you need to define a new container name (--name node2), a network alias (--network-alias node2), and a mapped port (-p 30003:22 -p 30004:80). docker run \ --name node1 \ --network test-network \ --network-alias node1 \ --privileged=true \ -dit \ -m 1500M \ -w ~/ \ -v /root/docker/node1:/root \ -p 30001:22 \ -p 30002:80 \ registry.cn-shanghai.aliyuncs.com/exposure/centos:7.8.2003_v1 \ /usr/sbin/init Explanation of each parameter in the command: # docker run \ # --name node1 \ Specifies the container name is node1 # --network test-network \ Use the network named test-network# --network-alias node1 \ Specify the network alias as node1, which is equivalent to the domain name# --privileged=true \ Specify a privileged container with full root permissions# -dit \ Equivalent to running the container in the background (-d), running the container in interactive mode (-i), and reallocating a pseudo input terminal (-t) for the container. -i and -t are generally used at the same time# -m 1500M \ Limit the container's memory usage to 1500 megabytes# -w ~/ \ Working directory, the directory after entering the container is the current user directory# -v /root/docker/node1:/root Mount the host/root/docker/node1 directory to the container/root directory, and the contents under the directory can be seen by each other# -p 30001:22 \ Map the host's 30001 port to the container's 22 port. Accessing the container's 22 port through the host's 30001 port is equivalent to accessing the container's 22 port# -p 30002:80 \ # registry.cn-shanghai.aliyuncs.com/exposure/centos:7.8.2003_v1 \ Use the image repository and tag/version number # /usr/sbin/init \ After the container is started, execute this command to prepare the environment for software execution, including the system host name, network settings, language, file system format, and startup of other services, etc. Connecting ContainersEnter the container from the host command line # Enter the container docker exec -it node1 /bin/bash # Exit the container exit Remote connection: Access the CentOS 7 container through the host IP and port (the one that maps the container port 22) Containers access each otherIn the same network, containers access each other through network aliases (--network-alias). In the figure below, we are connected to the node2 container. We can ping node1 in the container and the network is accessible. Reference LinksNovice Tutorial - Docker Commands This is the end of this article about the implementation steps of creating a CentOS container through Docker. For more relevant content about creating a CentOS container with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: The failure to play flv/MP4 and other video files on the website is related to the MIME type.
>>: Two ways to prohibit clearing the input text input cache in html
MySQL supports many data types, and choosing the ...
Table of contents Preface Introduction to Session...
What is ssh Administrators can log in remotely to...
LocalStorage stores Boolean values Today, when I ...
1. Nginx service foundation Nginx (engine x) is d...
IE10 provides a quick clear button (X icon) and a ...
HTML meta viewport attribute description What is ...
Copy code The code is as follows: <a href=# ti...
This article example shares the specific code of ...
Basic introduction to robots.txt Robots.txt is a p...
1 Introduction to HTML 1.1 First experience with ...
1. Previous versions yum remove docker docker-cli...
<br />Previously, we learned how to set cell...
Table of contents Preface Installation and Usage ...
Introduction to MySQL Window Functions MySQL has ...