如何自己定制一个docker镜像?
-
在ctftraining里面有很多优秀的镜像,比如
ctftraining/base_image_nginx_mysql_php_73 ctftraining/base_image_nginx_mysql_php_56 ctftraining/base_image_nginx_php_73 ctftraining/base_image_nginx_php_56
-
每个镜像具体内容从名字中都显而易见,实际使用起来也非常方便(比起Docker hub上其他的镜像来说)
-
但是当我在出一道关于php 反序列化 魔术方法 __wakeup 绕过的时候,即PHP反序列化漏洞CVE-2016-7124的时候,因为这个漏洞的影响范围是
PHP5 < 5.6.25 PHP7 < 7.0.10
-
但是ctftraining里面的php版本是5.6.40,也就是大于了5.6.25,但我又想出这道题那怎么办呢?只能自己重新组装镜像了。
-
试了Docker hub上很多有关nginx_php_55的镜像,都不太符合正常的使用习惯,也不太会改nginx.conf配置文件…所以我想去看看ctftraining的基础镜像是怎么构建的,结果在Github上成功找到CTFTraining/base_image_nginx_php_56: Base image For Web By Nginx + PHP 5.6 (github.com)
-
我们克隆下来之后,看到了它的Dockerfile
FROM php:5.6-fpm-alpine LABEL Organization="CTFTraining" Author="Virink <virink@outlook.com>" LABEL Author="wuuconix <wuuconix@gmail.com>" LABEL Blog="https://blog.csdn.net/Cypher_X" COPY _files /tmp/ COPY src /var/www/html RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk add --update --no-cache nginx \ && mkdir /run/nginx \ # configure file && mv /tmp/flag.sh /flag.sh \ && mv /tmp/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint \ && chmod +x /usr/local/bin/docker-php-entrypoint \ && mv /tmp/nginx.conf /etc/nginx/nginx.conf \ && chown -R www-data:www-data /var/www/html \ # clear && rm -rf /tmp/* # && rm -rf /etc/apk WORKDIR /var/www/html EXPOSE 80 VOLUME ["/var/log/nginx"] CMD ["/bin/bash", "-c", "docker-php-entrypoint"]
-
非常的优美简洁啊,就是看不懂( 然后我又找到了php_73的Dockerfile
FROM php:7.3-fpm-alpine LABEL Organization="CTFTraining" Author="Virink <virink@outlook.com>" # MAINTAINER Virink@CTFTraining <virink@outlook.com> COPY _files /tmp/ COPY src /var/www/html RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk add --update --no-cache nginx \ && mkdir /run/nginx \ # configure file && mv /tmp/flag.sh /flag.sh \ && mv /tmp/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint \ && chmod +x /usr/local/bin/docker-php-entrypoint \ && mv /tmp/nginx.conf /etc/nginx/nginx.conf \ && chown -R www-data:www-data /var/www/html \ # clear && rm -rf /tmp/* WORKDIR /var/www/html EXPOSE 80 VOLUME ["/var/log/nginx"] CMD ["/bin/bash", "-c", "docker-php-entrypoint"]
-
经过肉眼比对后,我发现几乎一致,只是把FROM FROM php:5.6-fpm-alpine 改成了 FROM php:7.3-fpm-alpine
-
那我直接把5.6改成5.5是不是就行了呢?我便去Docker hub上搜索是否有 php:5.5-fpm-alpine 结果还真有
-
改后直接build 发现遇到了错误。
-
它提示 /bin/bash: no such file or directory: unknow
-
可能是这个版本的php容器中没有bash,所以改成sh
FROM php:5.5-fpm-alpine LABEL Author="wuuconix <wuuconix@gmail.com>" LABEL Blog="https://blog.csdn.net/Cypher_X" COPY _files /tmp/ COPY src /var/www/html RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk add --update --no-cache nginx \ && mkdir /run/nginx \ # configure file && mv /tmp/flag.sh /flag.sh \ && mv /tmp/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint \ && chmod +x /usr/local/bin/docker-php-entrypoint \ && mv /tmp/nginx.conf /etc/nginx/nginx.conf \ && chown -R www-data:www-data /var/www/html \ # clear && rm -rf /tmp/* # && rm -rf /etc/apk WORKDIR /var/www/html EXPOSE 80 VOLUME ["/var/log/nginx"] CMD ["/bin/sh", "-c", "docker-php-entrypoint"]
-
改后成功运行容器
-
之后就可以愉快出题啦
-
分享github以及Docker Hub