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

Detailed explanation of CSS multiple three-column adaptive layout implementation

Preface In order to follow the conventional WEB l...

Sample code for html list box, text field, and file field

Drop-down box, text field, file field The upper p...

Comprehensive understanding of line-height and vertical-align

Previous words Line-height, font-size, and vertica...

Docker custom network detailed introduction

Table of contents Docker custom network 1. Introd...

How to install PHP7 Redis extension on CentOS7

Introduction In the previous article, we installe...

Solution to inconsistent display of cursor size in input box

The cursor size in the input box is inconsistent T...

jQuery+Ajax to achieve simple paging effect

This article shares the specific code of jquery+A...

HTML image img tag_Powernode Java Academy

summary Project description format <img src=&q...

Share 13 excellent web wireframe design and production tools

When you start working on a project, it’s importa...

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

HTML+CSS+JavaScript to create a simple tic-tac-toe game

Table of contents Implementing HTML Add CSS Imple...

Detailed explanation of the usage of compose function and pipe function in JS

Table of contents compose function Array.prototyp...

Detailed explanation of four solutions to floating problems in CSS layout

1. Cause: The effect after the subbox is set to f...

Implementation steps for installing java environment in docker

This article is based on Linux centos8 to install...