栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

基于 alpine 制作 httpd 镜像

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于 alpine 制作 httpd 镜像

基于 alpine 制作 httpd 镜像

文章目录
    • 基于 alpine 制作 httpd 镜像
      • 1. 拉取镜像
      • 2. 做好准备工作,创建工作目录
      • 3. 用 alpine 运行一个容器
      • 4.编写Dockerfile文件
        • 4.1 第一个Dockerfile文件
        • 4.2 编写第二个Dockerfile文件
        • 4.2 编写第三个Dockerfile文件,并写install.sh
      • 5. 制作镜像
      • 6. 测试
      • 7. 上传
      • 8. podman

1. 拉取镜像
[root@SYL4 ~]# docker pull alpine
2. 做好准备工作,创建工作目录
[root@SYL4 ~]# mkdir apacache
[root@SYL4 ~]# ls
anaconda-ks.cfg  apacache  httpd  muchen  nginx
[root@SYL4 ~]# cp -r httpd/files/ apacache/
[root@SYL4 ~]# 
[root@SYL4 ~]# cd apacache/
[root@SYL4 apacache]# 
[root@SYL4 apacache]# ls
files
[root@SYL4 apacache]# ls files/
apr-1.7.0.tar.gz       httpd-2.4.53.tar.gz
apr-util-1.6.1.tar.gz  install.sh
[root@SYL4 apacache]# vim Dockerfile
[root@SYL4 apacache]# 

将文件传到容器里面
[root@SYL4 apacache]# docker cp files 445cd44463d4:/tmp/
3. 用 alpine 运行一个容器
[root@SYL4 ~]# docker run -it --rm alpine /bin/sh
/ # adduser -SHs /sbin/nologin apache
/ # id apache
uid=100(apache) gid=65533(nogroup) groups=65533(nogroup),65533(nogroup)
/ # 
/ # cd /etc/apk
/etc/apk # ls
arch               protected_paths.d  world
keys               repositories
/etc/apk # cat repositories 
https://dl-cdn.alpinelinux.org/alpine/v3.15/main
https://dl-cdn.alpinelinux.org/alpine/v3.15/community
/etc/apk # sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' 
/etc/apk/repositories 
/etc/apk # cat repositories 
https://mirrors.aliyun.com/alpine/v3.15/main
https://mirrors.aliyun.com/alpine/v3.15/community
/etc/apk # 
~ # apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool make gcc libc-dev
~ # cd /tmp/
/tmp # ls
files
/tmp # mv files/* .
/tmp # ls
apr-1.7.0.tar.gz       httpd-2.4.53.tar.gz
apr-util-1.6.1.tar.gz  install.sh
files
/tmp # rm -rf files
/tmp # tar xf apr-1.7.0.tar.gz 
/tmp # tar xf apr-util-1.6.1.tar.gz 
/tmp # tar xf httpd-2.4.53.tar.gz


/tmp # cd /tmp/apr-1.7.0/
/tmp/apr-1.7.0 # sed -i '/$RM "$cfgfile"/d' configure
/tmp/apr-1.7.0 # ./configure --prefix=/usr/local/apr
/tmp/apr-1.7.0 # make
/tmp/apr-1.7.0 # make install


/tmp/apr-1.7.0 # cd ../apr-util-1.6.1/
/tmp/apr-util-1.6.1 # 
/tmp/apr-util-1.6.1 # ./configure --prefix=/usr/local/apr-util --w
ith-apr=/usr/local/apr
/tmp/apr-util-1.6.1 # make
/tmp/apr-util-1.6.1 # make install


/tmp # cd httpd-2.4.53/
/tmp/httpd-2.4.53 # ./configure --prefix=/usr/local/apache 
>         --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
/tmp/httpd-2.4.53 # make
/tmp/httpd-2.4.53 # make install


/ # du -sh *
1.5M    bin
0       dev
588.0K  etc
0       home
4.0M    lib
0       media
0       mnt
0       opt
0       proc
8.0K    root
0       run
96.0K   sbin
0       srv
0       sys
127.4M  tmp
173.8M  usr
0       var
/ # 
4.编写Dockerfile文件 4.1 第一个Dockerfile文件
[root@SYL4 apacache]# vim Dockerfile
[root@SYL4 apacache]# cat Dockerfile
FROM alpine

LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"

ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH

EXPOSE 80 443

ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD files/httpd-${VERSION}.tar.gz /tmp/

RUN adduser -SHs /sbin/nologin apache && 
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && 
    apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool make gcc libc-dev && 
    cd /tmp/apr-1.7.0/ && 
    sed -i '/$RM "$cfgfile"/d' configure && 
    ./configure --prefix=/usr/local/apr && 
    make && 
    make install && 
    cd ../apr-util-1.6.1/ && 
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && 
    make && 
    make install && 
    cd ../httpd-${VERSION} && 
    ./configure --prefix=/usr/local/apache 
        --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 

WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 apacache]# 
4.2 编写第二个Dockerfile文件
[root@SYL4 apacache]# vim Dockerfile
[root@SYL4 apacache]# cat Dockerfile 
FROM alpine

LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"

ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH

EXPOSE 80 443

ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD files/httpd-${VERSION}.tar.gz /tmp/

RUN adduser -SHs /sbin/nologin apache && 
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && 
    apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool make gcc libc-dev && 
    cd /tmp/apr-1.7.0/ && 
    sed -i '/$RM "$cfgfile"/d' configure && 
    ./configure --prefix=/usr/local/apr && 
    make && 
    make install && 
    cd ../apr-util-1.6.1/ && 
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && 
    make && 
    make install && 
    cd ../httpd-${VERSION} && 
    ./configure --prefix=/usr/local/apache 
        --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 && 
    apk del --no-cache -U make gcc libc-dev && 
    rm -rf /tmp/*

WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 apacache]#
4.2 编写第三个Dockerfile文件,并写install.sh
[root@SYL4 apacache]# vim Dockerfile 
[root@SYL4 apacache]# cat Dockerfile 
FROM alpine

LABEL MAINTAINER "xiaoyinguhong 3066347695@qq.com"

ENV VERSION 2.4.53
ENV PATH /usr/local/apache/bin:$PATH

EXPOSE 80 443

ADD files/apr-1.7.0.tar.gz /tmp/
ADD files/apr-util-1.6.1.tar.gz /tmp/
ADD files/httpd-${VERSION}.tar.gz /tmp/
ADD files/install.sh /tmp/

RUN /bin/sh /tmp/install.sh

WORKDIR /usr/local/apache
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/httpd"]
[root@SYL4 apacache]# 

install.sh
[root@SYL4 apacache]# ls
Dockerfile  files
[root@SYL4 apacache]# cp Dockerfile files/install.sh
[root@SYL4 apacache]# vim files/install.sh 
[root@SYL4 apacache]# cat files/install.sh 
#!/bin/sh

adduser -SHs /sbin/nologin apache && 
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && 
apk add --no-cache -U openssl-dev pcre-dev expat-dev libtool make gcc libc-dev && 
cd /tmp/apr-1.7.0/ && 
sed -i '/$RM "$cfgfile"/d' configure && 
./configure --prefix=/usr/local/apr && 
make && 
make install && 
cd ../apr-util-1.6.1/ && 
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && 
make && 
make install && 
cd ../httpd-${VERSION} && 
./configure --prefix=/usr/local/apache 
        --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 && 
apk del --no-cache -U make gcc libc-dev && 
rm -rf /tmp/*
[root@SYL4 apacache]# 
5. 制作镜像
[root@SYL4 apacache]# docker build -t httpd:alpine-2012.1 .
[root@SYL4 ~]# docker image ls
REPOSITORY            TAG             IMAGE ID       CREATED          SIZE
httpd                 alpine-2012.1   2c094eddaaf4   24 seconds ago   292MB

[root@SYL4 apacache]# docker build -t httpd:alpine-2012.2 .
[root@SYL4 ~]# docker image ls
REPOSITORY            TAG             IMAGE ID       CREATED          SIZE
httpd                 alpine-2012.2   5981af9b8249   33 seconds ago   112MB
httpd                 alpine-2012.1   2c094eddaaf4   10 minutes ag


[root@SYL4 apacache]# docker build -t httpd:alpine-2012.3 .
[root@SYL4 apacache]# docker image ls
REPOSITORY            TAG             IMAGE ID       CREATED          SIZE
httpd                 alpine-2012.3   566d506ee81c   2 minutes ago    112MB
httpd                 alpine-2012.2   5981af9b8249   17 minutes ago   112MB
httpd                 alpine-2012.1   2c094eddaaf4   27 minutes ago   292MB
6. 测试
[root@SYL4 ~]# docker run -d --rm --name web httpd:alpine-2012.1
e0f630a049e1b257aecef86f7f9ba2ace83e719f3e3154128e29832f57fafa7f
[root@SYL4 ~]# docker ps 
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS             NAMES
e0f630a049e1   httpd:alpine-2012.1   "/usr/local/apache/b…"   8 seconds ago   Up 6 seconds   80/tcp, 443/tcp   web
445cd44463d4   alpine                "/bin/sh"                2 hours ago     Up 2 hours                       charming_banach
[root@SYL4 ~]# 
[root@SYL4 ~]# curl 172.17.0.3

It works! [root@SYL4 ~]#

7. 上传
[root@SYL4 ~]# docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@SYL4 ~]# docker tag httpd:alpine-2012.3 xiaoyinguhong/httpd:alpine-2012.3
[root@SYL4 ~]# docker push xiaoyinguhong/httpd:alpine-2012.3
The push refers to repository [docker.io/xiaoyinguhong/httpd]
090fb243f7cf: Pushed 
ec0b7536b6a7: Pushed 
899c56408e76: Pushed 
b236af6114aa: Pushed 
1baedc566cbd: Pushed 
8d3ac3489996: Mounted from library/alpine 
alpine-2012.3: digest: sha256:316264085747290adb0701664175a4816b2245eeae9951e5078de5ce57077354 size: 1579
[root@SYL4 ~]# 
8. podman
  • Podman是一个无守护进程的容器引擎,用于在Linux系统上开发,管理和运行Open Container Initiative(OCI)容器和容器镜像。

  • Podman提供了一个与Docker兼容的命令行前端,它可以简单地作为Docker cli,简单地说你可以直接添加别名:alias docker = podman来使用podman。

  • Podman控制下的容器可以由root用户运行,也可以由非特权用户运行。Podman管理整个容器的生态系统,其包括pod,容器,容器镜像,和使用libpod library的容器卷。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/868544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号