螺蛳壳里做道场:老破机搭建的私人数据中心---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 |

相关推荐
烤麻辣烫1 小时前
黑马程序员苍穹外卖(新手)DAY6
java·开发语言·学习·spring·intellij-idea
i***22071 小时前
springboot整合libreoffice(两种方式,使用本地和远程的libreoffice);docker中同时部署应用和libreoffice
spring boot·后端·docker
Xudde.3 小时前
Quick2靶机渗透
笔记·学习·安全·web安全·php
AA陈超3 小时前
Git常用命令大全及使用指南
笔记·git·学习
羑悻的小杀马特4 小时前
轻量跨云·掌控无界:Portainer CE + cpolar 让远程容器运维像点外卖一样简单——免复杂配置,安全直达对应集群
运维·网络·安全·docker·cpolar
麦麦在写代码4 小时前
前端学习5
前端·学习
降临-max5 小时前
JavaSE---网络编程
java·开发语言·网络·笔记·学习
大白的编程日记.6 小时前
【计算网络学习笔记】MySql的多版本控制MVCC和Read View
网络·笔记·学习·mysql
q***49457 小时前
Ubuntu介绍、与centos的区别、基于VMware安装Ubuntu Server 22.04、配置远程连接、安装jdk+Tomcat
java·ubuntu·centos
u***42078 小时前
Golang 构建学习
开发语言·学习·golang