基于 alpine 制作 httpd 镜像

基于 alpine 制作 httpd 镜像

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
<html><body><h1>It works!</h1></body></html>
[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 ~]# 
  • 在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值