其他分享
首页 > 其他分享> > podman用脚本和dockerfile做apache编译安装镜像(alpine版)

podman用脚本和dockerfile做apache编译安装镜像(alpine版)

作者:互联网

podman用脚本和dockerfile做apache编译安装镜像(alpine版)

alpine系统是什么

Alpine Linux 是一个基于 musl libc 和 busybox 的面向安全的轻量级 Linux 发行版。

alpine系统的特点

alpine镜像下载

alpine官网

alpine国内源

清华大学:https://mirror.tuna.tsinghua.edu.cn/alpine/
阿里云:https://mirrors.aliyun.com/alpine/
网易:http://mirrors.163.com/

更换apk源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

alpine基础命令

apk update 		//更新最新镜像源列表
 
apk search 		//查找所以可用软件包
 
apk search -v 		//查找所以可用软件包及其描述内容
 
apk search -v ‘acf*’ 		//通过软件包名称查找软件包
 
apk search -v -d ‘docker’ 		//通过描述文件查找特定的软件包
 
apk add openssh 		//安装一个软件
 
apk add openssh openntp vim 		//安装多个软件
 
apk add --no-cache mysql-client 		//不使用本地镜像源缓存,相当于先执行update,再执行add
 
apk info 				//列出所有已安装的软件包
 
apk info -a zlib 		//显示完整的软件包信息
 
apk info --who-owns /sbin/lbu 			//显示指定文件属于的包
 
apk upgrade 				//升级所有软件
 
apk upgrade openssh 		//升级指定软件
 
apk upgrade openssh openntp vim 		//升级多个软件
 
apk add --upgrade busybox 				//指定升级部分软件包
 
apk del openssh 			//删除一个软件

服务管理

alpine没有使用fedora的systemctl来进行服务管理,使用的是RC系列命令:

rc-update 			//主要用于不同运行级增加或者删除服务

rc-status 			//主要用于运行级的状态管理

rc-service 			//主用于管理服务的状态

rc-status -a 		//列出系统所有服务

关闭系统

reboot 		//重启系统

poweroff 	//关机

podman用dockerfile做alpine编译安装镜像

创建目录并下载所需安装包

[root@localhost ~]#mkdir -p /srv/web
[root@localhost ~]# cd /srv/web/
[root@localhost web]# ls
[root@localhost web]# echo "China" > index.html
[root@localhost web]# cat index.html 
China
[root@localhost ~]# mkdir httpd
[root@localhost ~]# cd httpd/
[root@localhost httpd]# mkdir files
[root@localhost httpd]# touch Dockerfile
[root@localhost httpd]# ls
Dockerfile  files
[root@localhost httpd]# cd files/
[root@localhost files]# wget http://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
[root@localhost files]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
[root@localhost files]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
[root@localhost files]# ls
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz

编写entrypoint.sh脚本

[root@localhost files]# vim entrypoint.sh
[root@localhost files]# cat entrypoint.sh 
#!/bin/bash

sed -i '/^ServerName/s/#//g' /usr/local/apache/conf/httpd/conf

exec "$@"

[root@localhost files]# chmod +x entrypoint.sh
[root@localhost files]# ll
总用量 11136
-rw-r--r--. 1 root root 1093896 4月   5 2019 apr-1.7.0.tar.gz
-rw-r--r--. 1 root root  554301 10月 23 2017 apr-util-1.6.1.tar.gz
-rwxr-xr-x. 1 root root      87 8月  30 21:23 entrypoint.sh
-rw-r--r--. 1 root root 9743277 6月   8 16:42 httpd-2.4.54.tar.gz

编写dockerfile

[root@localhost files]# cd ..
[root@localhost httpd]# vim Dockerfile
[root@localhost httpd]# cat Dockerfile 
FROM alpine

LABEL MANTAINER "JL 1548126326@qq.com"

ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.54

ADD files/* /tmp/

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update && \
    adduser -SHs /sbin/nologin apache && \
    apk add --no-cache -U gcc libc-dev make expat-dev pcre-dev openssl-dev libtool && \
    cd /tmp/apr-${apr_version} && \
    sed -i '/$RM "$cfgfile"/d' configure && \
    ./configure --prefix=/usr/local/apr && \
    make && make install && \
    cd /tmp/apr-util-${apr_util_version} && \
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
    make && make install && \
    cd /tmp/httpd-${httpd_version} && \
    ./configure --prefix=/usr/local/apache \
    --sysconfdir=/etc/httpd24 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork && \
    make && make install && \
    mv /tmp/entrypoint.sh / && \
    apk del gcc make && \
    rm -rf /tmp/* /var/cache/*

EXPOSE 80
WORKDIR /usr/local/apache
CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]
ENTRYPOINT ["/bin/bash","/entrypoint.sh"]

创建镜像

[root@localhost httpd]# cd
[root@localhost ~]# podman build -t feigeaq/httpd:v2 httpd/
[root@localhost ~]# podman images
REPOSITORY                TAG         IMAGE ID      CREATED             SIZE
localhost/feigeaq/httpd   v2          5b312457b7af  About a minute ago  128 MB
docker.io/library/alpine  latest      c059bfaa849c  9 months ago        5.87 MB

创建容器,链接外部存储,并测试

[root@localhost ~]# podman run -d --name web -p 80:80 -v /srv/web/://usr/local/apache/htdocs/:Z feigeaq/httpd:v2


[root@localhost web]# podman ps 
CONTAINER ID  IMAGE                       COMMAND               CREATED         STATUS             PORTS               NAMES
7f3dc425697b  localhost/feigeaq/httpd:v2  /usr/local/apache...  10 minutes ago  Up 10 minutes ago  0.0.0.0:80->80/tcp  web


[root@localhost ~]# curl localhost:80
China

上传镜像到dockerhub

[root@localhost ~]# podman images
REPOSITORY                TAG         IMAGE ID      CREATED         SIZE
localhost/feigeaq/httpd   v2          5b312457b7af  38 minutes ago  128 MB
docker.io/library/alpine  latest      c059bfaa849c  9 months ago    5.87 MB
[root@localhost ~]# podman push feigeaq/httpd:v2
Getting image source signatures
Copying blob 8d3ac3489996 done  
Copying blob bdb16d456f26 done  
Copying blob 796a38c423e2 done  
Copying config 5b312457b7 done  
Writing manifest to image destination
Storing signatures

标签:httpd,apk,--,root,podman,apr,apache,dockerfile,localhost
来源: https://www.cnblogs.com/soap-bubble/p/16644220.html