Docker容器基础镜像安装软件,可以作为centos完整版和ubuntu完整版
使用,就如同操作系统一般。
第一部分:centos
1、创建容器网卡
docker network create --subnet=172.172.1.0/24 pg-network
[root@openstack ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
4aeda955799e bridge bridge local
42c213021c95 host host local
a02badcd56ef none null local
8f19426adf98 pg-network bridge local
[root@openstack ~]# docker network inspect pg-network
[
{
"Name": "pg-network",
"Id": "8f19426adf98cb079ad1cc6b390a8d09a9bb6f3cef22acd905599b3c4634aa6f",
"Created": "2023-12-07T09:15:48.653438651+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.172.1.0/24"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"1fbc970cda7247fd1828a493a3d4bc8121abb47a469c0375357fc2943f56ae1a": {
"Name": "pgtest",
"EndpointID": "265cb278148a9a9403cb8a4d6b11ca4637f572cdc397034955f814cf66726558",
"MacAddress": "02:42:ac:ac:01:02",
"IPv4Address": "172.172.1.2/24",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
2、获取基础镜像
[root@openstack ~]# docker images|grep centos
centos 7.6.1810 f1cb7c7d58b7 4 years ago 202MB
You have new mail in /var/spool/mail/root
3、创建容器
docker run -d --name pgtest -h pgtest \
--net=pg-network --ip 172.172.1.2 \
-p 65432:5432 \
-v /sys/fs/cgroup:/sys/fs/cgroup \
--privileged=true centos:7.6.1810 \
/usr/sbin/init
3、yum安装软件
yum -y update && \
yum -y install wget && \
yum -y install tar && \
yum -y install bzip2 && \
yum -y install unzip && \
yum -y install net-tools && \
yum -y install tcpdump && \
yum -y install telnet && \
yum -y install vim && \
yum -y install git && \
yum -y install openssh-server && \
yum -y install java-1.8.0-openjdk && \
yum -y install perl && \
yum -y install python && \
yum -y install ruby && \
yum -y install php && \
yum -y install gcc && \
yum -y install make && \
yum -y install autoconf && \
yum -y install automake && \
yum -y install libtool && \
yum -y install libxml2-devel && \
yum -y install libpng-devel && \
yum -y install libjpeg-devel && \
yum -y install freetype-devel && \
yum -y install openssl-devel && \
yum -y install libcurl-devel && \
yum -y install libxslt-devel && \
yum -y install bzip2-devel && \
yum -y install readline-devel && \
yum -y install sqlite-devel && \
yum -y install postgresql-devel && \
yum -y install mariadb-server && \
yum -y install httpd && \
yum -y install vsftpd && \
yum -y install epel-release && \
yum -y install supervisor && \
yum -y install libselinux-utils && \
yum -y install firewalld && \
yum -y install lrzsz && \
yum -y install NetworkManager &&\
yum -y clean all
4、安装iproute2
iproute是Linux下一个网络管理工具包合集,用于取代先前的如ifconfig,route,ifup,ifdown,netstat等历史网络管理工具。该工具包功能强大,它通过网络链路套接字接口与内核进行联系。iproute的用户界面比net-tools的用户界面要更直观。对网络资源比如链路、IP地址、路由和隧道等用“对象”抽象进行了恰当的定义,因此可以使用一致的语法来管理不同的对象。
下载网址:
https://www.kernel.org/pub/linux/utils/net/iproute2/
配置hosts解析
[root@pgtest /]# echo "147.75.48.161 mirrors.edge.kernel.org" >> /etc/hosts
查看centos7.6已安装的参考版本
[root@openstack ~]# rpm -qa|grep iproute
iproute-4.11.0-30.el7.x86_64
获取软件包
https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.11.0.tar.gz
编译源码安装
安装依赖
[root@pgtest data]#yum install -y gcc bison flex
解压包
[root@pgtest data]#tar -xzf iproute2-3.17.0.tar.gz
[root@pgtest data]#cd iproute2-3.17.0
[root@pgtest iproute2-4.11.0]#sed -i '/^TARGETS/s@arpd@@g' misc/Makefile
[root@pgtest iproute2-4.11.0]#make SBINDIR=/sbin
[root@pgtest iproute2-4.11.0]#make SBINDIR=/sbin install
可以使用ip命令了
[root@pgtest iproute2-4.11.0]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
14: eth0@if15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:ac:01:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.172.1.2/24 brd 172.172.1.255 scope global eth0
valid_lft forever preferred_lft forever
[root@pgtest iproute2-4.11.0]#
5、docker将容器打包成镜像
[root@openstack ~]# docker stop pgtest
pgtest
[root@openstack ~]# docker commit pgtest centos:7.6
sha256:c776dc868dcc5dca7279baf6b80ae552f136d2f1d4c7d74f1670468c77f37389
[root@openstack ~]# docker images |grep centos
centos 7.6 c776dc868dcc 14 seconds ago 1.4GB
centos 7.6.1810 f1cb7c7d58b7 4 years ago 202MB
第二部分:ubuntu
1、拉取基础镜像
[root@openstack ~]# docker pull ubuntu:20.04
20.04: Pulling from library/ubuntu
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Image is up to date for ubuntu:20.04
docker.io/library/ubuntu:20.04
[root@openstack ~]# docker images|grep ubuntu
ubuntu 20.04 ba6acccedd29 2 years ago 72.8MB
2、启动容器
[root@openstack ~]# docker run -d -it --name ubuntu2004test -h ubuntu2004test ubuntu:20.04
611ff690cc7832461de640784c1d3516a0f1ffc2b8f3d5a8eea6d6a3b677a538
进入容器
[root@openstack ~]# docker exec -it ubuntu2004test bash
root@ubuntu2004test:/#
3、ubuntu安装基础依赖软件,可选择性安装
更新软件源
root@121bc3b6fbfc:/etc# apt-get update
安装软件
root@121bc3b6fbfc:/etc#
apt -y install wget && \
apt -y install tar && \
apt -y install bzip2 && \
apt -y install unzip && \
apt -y install net-tools && \
apt -y install tcpdump && \
apt -y install telnet && \
apt -y install vim && \
apt -y install git && \
apt -y install openssh-server && \
apt -y install java-1.8.0-openjdk && \
apt -y install perl && \
apt -y install python && \
apt -y install ruby && \
apt -y install php && \
apt -y install gcc && \
apt -y install make && \
apt -y install autoconf && \
apt -y install automake && \
apt -y install libtool && \
apt -y install libxml2-devel && \
apt -y install libpng-devel && \
apt -y install libjpeg-devel && \
apt -y install freetype-devel && \
apt -y install openssl-devel && \
apt -y install libcurl-devel && \
apt -y install libxslt-devel && \
apt -y install bzip2-devel && \
apt -y install readline-devel && \
apt -y install sqlite-devel && \
apt -y install postgresql-devel && \
apt -y install mariadb-server && \
apt -y install httpd && \
apt -y install vsftpd && \
apt -y install epel-release && \
apt -y install supervisor && \
apt -y install libselinux-utils && \
apt -y install firewalld && \
apt -y install lrzsz && \
apt -y install NetworkManager
4、ubunt20.04安装iproute2
进入网站 [https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/](https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/)
下载某版本压缩包
下载软件包
root@ubuntu2004test:/data/iproute2-4.10.0# wget https://mirrors.edge.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.10.0.tar.gz
root@ubuntu2004test:/data/iproute2-4.10.0# tar xvf iproute2-4.10.0.tar.gz
安装iproute2依赖包
sudo apt-get install bison flex
编译安装
sudo make
sudo make install