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

MySQL data type optimization principles

MySQL supports many data types, and choosing the ...

How to use SessionStorage and LocalStorage in Javascript

Table of contents Preface Introduction to Session...

Implementation of ssh non-secret communication in linux

What is ssh Administrators can log in remotely to...

Solve the pitfall of storing boolean type values ​​in localstorage

LocalStorage stores Boolean values Today, when I ...

How to disable IE10's password clear text display and quick clear function

IE10 provides a quick clear button (X icon) and a ...

Description of meta viewport attribute in HTML web page

HTML meta viewport attribute description What is ...

HTML uses the title attribute to display text when the mouse hovers

Copy code The code is as follows: <a href=# ti...

Vue uses filters to format dates

This article example shares the specific code of ...

Robots.txt detailed introduction

Basic introduction to robots.txt Robots.txt is a p...

Introduction to HTML for front-end developers

1 Introduction to HTML 1.1 First experience with ...

Detailed tutorial on installing Docker on CentOS 8

1. Previous versions yum remove docker docker-cli...

How to set the border of a web page table

<br />Previously, we learned how to set cell...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

Mysql8.0 uses window functions to solve sorting problems

Introduction to MySQL Window Functions MySQL has ...