螺蛳壳里做道场:老破机搭建的私人数据中心---Centos下Docker学习04(环境准备)

4 创建docker容器

4.1创建网络

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@localhost wutool]# docker network create -d macvlan --subnet=192.168.137.0/24 --gateway=192.168.137.2 --ip-range=192.168.137.0/24 -o parent=ens33 nat 52af11381bfd655d175e4168265b2a507793e8fe48f119db846949ffd4dd27de [root@localhost wutool]# docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1 --ip-range=192.168.0.0/24 -o parent=ens36 wifi 9d3806a76de2546615867c70a5bc625b31e752cc1250476a58d3d8f403aabbd4 [root@localhost wutool]# docker network create -d macvlan --subnet=100.100.100.0/24 --gateway=100.100.100.99 --ip-range=100.100.100.0/24 -o parent=ens37 nei 09af87291ddd51c004c4c9d11da11dc3595e1e3a8c59f1c2c7109044eb8ed46e [root@localhost wutool]# docker network create -d macvlan --subnet=202.112.113.0/24 --gateway=202.112.113.99 --ip-range=202.112.113.0/24 -o parent=ens38 wai fbef905eb791f0e4cd7f4468323cf13e7a8a31fbef9862be2e99fcc6902b4fcd |
| Docker network create --d macvlan 创建的网络类型为 macvlan -d 为指定驱动 |
| --subnet=192.168.0.0/24 --ip-range=192.168.0.0/24指定子网和 ip 范围 |
| macvlan_mode=bridge |
| -o parent=ens32 给容器分配 ip 的母卡 |
| nei 命名 |

查看结果:

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@localhost wutool]# docker network ls NETWORK ID NAME DRIVER SCOPE 7b8bed01024a bridge bridge local 39af1a44d82f host host local 52af11381bfd nat macvlan local 09af87291ddd nei macvlan local ca64c7cfcc57 none null local fbef905eb791 wai macvlan local 9d3806a76de2 wifi macvlan local |

4.2 按照表3-2规划创建容器

各容器是以centos8镜像生成的,在/etc下创建一个cts8etc目录装库文件,并拖入8.5的repo文件,如图4-1所示:

图4- 1

创建下面各容器(暂时用最简单的方法)

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 67-68:67-68 --net wifi --ip 192.168.0.201 --name dhcp centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 53:53 --net wifi --ip 192.168.0.202 --name dns centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 2049:2049 --net wifi --ip 192.168.0.203 --name nfs centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 139-445:139-445 --net wifi --ip 192.168.0.204 --name samba centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 80:80 --net wifi --ip 192.168.0.205 --name apche centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 20-21:20-21 --net wifi --ip 192.168.0.206 --name ftp centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 25-110:25-110 --net wifi --ip 192.168.0.207 --name email centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d --net wifi --ip 192.168.0.208 --name proxy centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 69:69 --net wifi --ip 192.168.0.209 --name tftp centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 23:23 --net wifi --ip 192.168.0.210 --name telnet centos /usr/sbin/init docker run -itd -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /wutool:/wutool -v /mnt:/mnt -v /cts8etc/yum.repos.d:/etc/yum.repos.d -p 123:123 --net wifi --ip 192.168.0.222 --name ntp centos /usr/sbin/init |

先试一下ntp容器:

|-----------------------------------------------------------------------------------------------------|
| [root@localhost wutool]# docker start ntp ntp [root@localhost wutool]# docker exec -it ntp bash |

看看repo文件

|----------------------------------------------------------------------------------------------------------------|
| [root@f7f3368ab5c5 /]# cd /etc/yum.repos.d/ [root@f7f3368ab5c5 yum.repos.d]# ls Centos-vault-8.5.2111.repo |

改主机名

|------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@f7f3368ab5c5 yum.repos.d]# hostnamectl set-hostname ntp Could not set property: Failed to set static hostname: Device or resource busy |

会报错(bug),不理它,退出并重新进入

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@f7f3368ab5c5 yum.repos.d]# bash [root@ntp yum.repos.d]# exit [root@f7f3368ab5c5 yum.repos.d]# exit exit [root@localhost wutool]# docker exec -it ntp bash [root@ntp /]# |

更新容器的yum源:

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@ntp /]# yum makecache Failed to set locale, defaulting to C.UTF-8 CentOS-8.5.2111 - Base - mirrors.aliyun.com 1.1 MB/s | 4.6 MB 00:04 CentOS-8.5.2111 - Extras - mirrors.aliyun.com 27 kB/s | 10 kB 00:00 CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 1.2 MB/s | 8.4 MB 00:07 Metadata cache created. |

安装必要工具:

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools firewalld iptables-services [root@ntp /]# yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools firewalld iptables-services Failed to set locale, defaulting to C.UTF-8 Last metadata expiration check: 0:02:14 ago on Tue Oct 1 07:16:13 2024. Dependencies resolved. =========================================================================================================================== Package Architecture Version Repository Size =========================================================================================================================== Installing: device-mapper-persistent-data x86_64 0.9.0-4.el8 base 925 k ...... Complete! |

查看容器OS版本号:

|-----------------------------------------------------------------------|
| [root@ntp /]# cat /etc/redhat-release CentOS Linux release 8.4.2105 |

相关推荐
布鲁格若门2 分钟前
CentOS 7 桌面版安装 cuda 12.4
linux·运维·centos·cuda
Eternal-Student7 分钟前
【docker 保存】将Docker镜像保存为一个离线的tar归档文件
运维·docker·容器
不是二师兄的八戒9 分钟前
本地 PHP 和 Java 开发环境 Docker 化与配置开机自启
java·docker·php
码农小丘15 分钟前
一篇保姆式centos/ubuntu安装docker
运维·docker·容器
/**书香门第*/28 分钟前
Cocos creator 3.8 支持的动画 7
学习·游戏·游戏引擎·游戏程序·cocos2d
美式小田1 小时前
单片机学习笔记 9. 8×8LED点阵屏
笔记·单片机·嵌入式硬件·学习
Eternal-Student1 小时前
【1.2 Getting Started--->Installation Guide】
docker
猫爪笔记1 小时前
前端:HTML (学习笔记)【2】
前端·笔记·学习·html
-一杯为品-2 小时前
【51单片机】程序实验5&6.独立按键-矩阵按键
c语言·笔记·学习·51单片机·硬件工程
风尚云网3 小时前
风尚云网前端学习:一个简易前端新手友好的HTML5页面布局与样式设计
前端·css·学习·html·html5·风尚云网