Steps to create a CentOS container through Docker

Steps to create a CentOS container through Docker

Preface

First 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 <網絡名稱> .

docker network create test-network

List all networks under Docker and you can see test-network.

docker network ls

image-20211113112157290

Creating a container from a CentOS 7 image

Run docker run to use Alibaba Cloud's image repository to pull the packaged CentOS 7 Chinese version image (based on the centos:7.8.2003 image, JDK8, vim, lsof, wget, tree, python-devel, c compilation environment, and SSH are added) to create a CentOS 7 container. The system username and password are root and 666666 respectively.

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 Containers

Enter 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)

image-20211113151954206

Containers access each other

In 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.

image-20211113151707170

Reference Links

Novice 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:
  • Detailed explanation of the process of deploying MySql on Centos server and connecting to Navicat
  • Docker creates a centos container and downloads MySQL in the container to connect to MySQL locally

<<:  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

Recommend

HTML realizes real-time monitoring function of Hikvision camera

Recently the company has arranged to do some CCFA...

A complete list of commonly used MySQL functions (classified and summarized)

1. Mathematical Functions ABS(x) returns the abso...

Recommended 20 best free English handwriting fonts

Jellyka BeesAntique Handwriting [ank]* Jellyka Cut...

Vue custom component implements two-way binding

Scenario: The interaction methods between parent ...

The correct way to use Homebrew in Linux

Many people use Linux Homebrew. Here are three ti...

Samba server configuration under Centos7 (actual combat)

Samba Overview Samba is a free software that impl...

How to create a stylish web page design (graphic tutorial)

"Grand" are probably the two words that ...

Detailed explanation of the construction and use of docker private warehouse

1. Download the repository image docker pull regi...

Nginx configuration SSL and WSS steps introduction

Table of contents Preface 1. Nginx installation 1...

js array fill() filling method

Table of contents 1. fill() syntax 2. Use of fill...

Docker container operation instructions summary and detailed explanation

1. Create and run a container docker run -it --rm...

What are the new CSS :where and :is pseudo-class functions?

What are :is and :where? :is() and :where() are p...

Content-type description, that is, the type of HTTP request header

To learn content-type, you must first know what i...

A brief analysis of SQL examples for finding uncommitted transactions in MySQL

A long time ago, I summarized a blog post titled ...

How to design a web page? How to create a web page?

When it comes to understanding web design, many p...