Bootstrap

通过Docker封装镜像的方式完成Nginx的rpm包制作

实验背景:
Ubuntu系统上通过docker拉取centos8环境来制作nginx的rpm包,为了方便下次制作方便,简单封装了需要的Centos8的制作镜像,由于需要使用yum环境来安装所需要的命令和依赖库,为了保证docker容器能够连通外网,因此配置了docker的dns解析

一、查看宿主机dns

[root@localhost ~]# cat /etc/resolv.conf
#Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

二、将dns配置到/etc/docker/daemon.json

{
	"dns": ["114.114.114.114","8.8.8.8"]
}

三、重启docker

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

四、拉取docker的centos8镜像

docker pull pandemonium1986/centos8

五、封装镜像

cd /root
vim dockerfile
----------------------------------------------
FROM pandemonium1986/centos8:latest
RUN yum install -y kernel-headers kernel-devel gcc gcc-c++ make pcre pcre-devel openssl openssl-devel zlib zlib-devel  rpm-build
----------------------------------------------
docker build -f dockerfile .
docker run -it pandemonium1986/centos8:latest /bin/bash
docker cp nginx-1.26.2.tar.gz 镜像ID:/root
rpmbuild -ba nginx.sepc  #容器内执行生成编译目录
cp /root/nginx-1.26.2.tar.gz /rpmbuild/SOURCES
vim /root/rpmbuild/SPECS/nginx.sepc

内容如下:

Name: nginx
Version: 1.26.2
Release: el8
Summary: nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server
Group: Applications/Server
License: GPL
URL: http://nginx.org/
Source0: nginx-1.26.2.tar.gz
#BuildRequires: 
Requires: pcre-devel openssl-devel
%description
nginx is an HTTP and reverse proxy server.
%post
useradd nginx
%prep
%setup -q
%build
./configure
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/*
%changelog
rpmbuild -bb nginx.spec 完成rpm包的编译
cp /root/rpmbuild/RPMX/x86_64/nginx-1.26.2-el8.x86_64.rpm /root
rpm -ivh nginx-1.26.2-el8.x86_64.rpm  # 安装测试
;