螺蛳壳里做道场:老破机搭建的私人数据中心---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 分钟前
docker快速安装与配置mongoDB
mongodb·docker·容器
lulu_gh_yu18 分钟前
数据结构之排序补充
c语言·开发语言·数据结构·c++·学习·算法·排序算法
Re.不晚42 分钟前
Java入门15——抽象类
java·开发语言·学习·算法·intellij-idea
幼儿园老大*2 小时前
走进 Go 语言基础语法
开发语言·后端·学习·golang·go
2 小时前
开源竞争-数据驱动成长-11/05-大专生的思考
人工智能·笔记·学习·算法·机器学习
ctrey_2 小时前
2024-11-4 学习人工智能的Day21 openCV(3)
人工智能·opencv·学习
啦啦右一2 小时前
前端 | MYTED单篇TED词汇学习功能优化
前端·学习
阿尔帕兹2 小时前
构建 HTTP 服务端与 Docker 镜像:从开发到测试
网络协议·http·docker
霍格沃兹测试开发学社测试人社区3 小时前
软件测试学习笔记丨Flask操作数据库-数据库和表的管理
软件测试·笔记·测试开发·学习·flask
今天我又学废了3 小时前
Scala学习记录,List
学习