Dockerfile不会写怎么办,有它就够了

简介

image2df是一款将Docker镜像拉去下来转换成Dockerfile的产品,当我们初学dockerfile肯定会经常遇到镜像制作的各种坑,打包好了却跑不起来,这里我们就可以通过image2df拉取一些dockerfile去学习一下。

环境准备

检查本地Docker环境状态

[root@ecs-361333 ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:04:24 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:02:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

[root@ecs-361333 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-10-31 23:26:25 CST; 5 months 13 days ago
     Docs: https://docs.docker.com
 Main PID: 8718 (dockerd)
    Tasks: 27
   Memory: 1.0G
   CGroup: /system.slice/docker.service
           ├─   8718 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─1684105 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5244 -container-ip 172.17.0.2 -container-port 5244
           └─1684111 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5244 -container-ip 172.17.0.2 -container-port 5244

Apr 06 00:18:09 ecs-361333 dockerd[8718]: time="2023-04-06T00:18:09.011875579+08:00" level=error msg="Upload failed, retrying: dial tcp 1...timeout"
Apr 06 00:21:05 ecs-361333 dockerd[8718]: time="2023-04-06T00:21:05.991309583+08:00" level=error msg="Upload failed, retrying: dial tcp 1...timeout"
Apr 06 19:47:02 ecs-361333 dockerd[8718]: time="2023-04-06T19:47:02.135079445+08:00" level=info msg="Container failed to exit within 10s ...58016f5a
Apr 06 19:47:02 ecs-361333 dockerd[8718]: time="2023-04-06T19:47:02.779295831+08:00" level=info msg="ignoring event" container=fde1aed899...kDelete"
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
Hint: Some lines were ellipsized, use -l to show in full.

下载image2df镜像

[root@ecs-361333 ~]# docker pull cucker/image2df
Using default tag: latest
latest: Pulling from cucker/image2df
5843afab3874: Pull complete 
2dfaacf7024e: Pull complete 
2dbba127c6aa: Pull complete 
1a467efa2204: Pull complete 
865369a531d5: Pull complete 
474589c70e86: Retrying in 1 second 
a3b947cfda34: Download complete 
0449e7a0589e: Download complete 
latest: Pulling from cucker/image2df
5843afab3874: Pull complete 
2dfaacf7024e: Pull complete 
2dbba127c6aa: Pull complete 
1a467efa2204: Pull complete 
865369a531d5: Pull complete 
404ef7225327: Pull complete 
8692a4284c82: Pull complete 
07df60969536: Pull complete 
Digest: sha256:cd5fa4233cf5c7fa0cd35a222519babe951aa6bd599833468465a58ee2981802
Status: Downloaded newer image for cucker/image2df:latest
docker.io/cucker/image2df:latest

将设置别名

将image2df设置启动别名

echo "alias image2df='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock registry.baidubce.com/docker-hub/cucker/image2df:latest'" >> ~/.bashrc

重启,生效配置

source ~/.bashrc

验证

获取wordpress的Dockerfile文件

image2df wordpress:latest > dockerfile

查看dockerfile文件内容

[root@ecs-361333 ~]# ll
total 70968
-rw-r--r-- 1 root root     9798 Apr 15 16:21 dockerfile
[root@ecs-361333 ~]# cat dockerfile 

========== Dockerfile ==========
FROM wordpress:latest
RUN set -eux; \
        {
    
     \
                echo 'Package: php*'; \
        echo 'Pin: release *'; \
        echo 'Pin-Priority: -1'; \
        } > /etc/apt/preferences.d/no-debian-php
ENV PHPIZE_DEPS=autoconf \
                dpkg-dev \
                file \
                g++ \
                gcc \
                libc-dev \
                make \
                pkg-config \
                re2c
RUN set -eux; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                $PHPIZE_DEPS \
                ca-certificates \
                curl \
                xz-utils \
        ; \
        rm -rf /var/lib/apt/lists/*
ENV PHP_INI_DIR=/usr/local/etc/php
RUN set -eux; \
        mkdir -p "$PHP_INI_DIR/conf.d"; \
        [ ! -d /var/www/html ]; \
        mkdir -p /var/www/html; \
        chown www-data:www-data /var/www/html; \
        chmod 777 /var/www/html
ENV APACHE_CONFDIR=/etc/apache2
ENV APACHE_ENVVARS=/etc/apache2/envvars
RUN set -eux; \
        apt-get update; \
        apt-get install -y --no-install-recommends apache2; \
        rm -rf /var/lib/apt/lists/*; \
        sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS"; \
        . "$APACHE_ENVVARS"; \
        for dir in \
                "$APACHE_LOCK_DIR" \
                "$APACHE_RUN_DIR" \
                "$APACHE_LOG_DIR" \
        ; do \
                rm -rvf "$dir"; \
        mkdir -p "$dir"; \
        chown "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; \
        chmod 777 "$dir"; \
        done; \
        rm -rvf /var/www/html/*; \
        ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
        ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
        ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
        chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
RUN a2dismod mpm_event && a2enmod mpm_prefork
RUN {
    
     \
                echo '<FilesMatch \.php$>'; \
        echo '\tSetHandler application/x-httpd-php'; \
        echo '</FilesMatch>'; \
        echo; \
        echo 'DirectoryIndex disabled'; \
        echo 'DirectoryIndex index.php index.html'; \
        echo; \
        echo '<Directory /var/www/>'; \
        echo '\tOptions -Indexes'; \
        echo '\tAllowOverride All'; \
        echo '</Directory>'; \
        } | tee "$APACHE_CONFDIR/conf-available/docker-php.conf" \
        && a2enconf docker-php
ENV PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
ENV PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
ENV PHP_LDFLAGS=-Wl,-O1 -pie
ENV GPG_KEYS=42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312
ENV PHP_VERSION=7.4.27
ENV PHP_URL=https://www.php.net/distributions/php-7.4.27.tar.xz PHP_ASC_URL=https://www.php.net/distributions/php-7.4.27.tar.xz.asc
ENV PHP_SHA256=3f8b937310f155822752229c2c2feb8cc2621e25a728e7b94d0d74c128c43d0c
RUN set -eux; \
        savedAptMark="$(apt-mark showmanual)"; \
        apt-get update; \
        apt-get install -y --no-install-recommends gnupg dirmngr; \
        rm -rf /var/lib/apt/lists/*; \
        mkdir -p /usr/src; \
        cd /usr/src; \
        curl -fsSL -o php.tar.xz "$PHP_URL"; \
        if [ -n "$PHP_SHA256" ]; then \
                echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \
        fi; \
        if [ -n "$PHP_ASC_URL" ]; then \
                curl -fsSL -o php.tar.xz.asc "$PHP_ASC_URL"; \
        export GNUPGHOME="$(mktemp -d)"; \
        for key in $GPG_KEYS; do \
                        gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
        done; \
        gpg --batch --verify php.tar.xz.asc php.tar.xz; \
        gpgconf --kill all; \
        rm -rf "$GNUPGHOME"; \
        fi; \
        apt-mark auto '.*' > /dev/null; \
        apt-mark manual $savedAptMark > /dev/null; \
        apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
COPY file:ce57c04b70896f77cc11eb2766417d8a1240fcffe5bba92179ec78c458844110 in /usr/local/bin/
RUN set -eux; \
        savedAptMark="$(apt-mark showmanual)"; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                apache2-dev \
                libargon2-dev \
                libcurl4-openssl-dev \
                libonig-dev \
                libreadline-dev \
                libsodium-dev \
                libsqlite3-dev \
                libssl-dev \
                libxml2-dev \
                zlib1g-dev \
        ; \
        export \
                CFLAGS="$PHP_CFLAGS" \
                CPPFLAGS="$PHP_CPPFLAGS" \
                LDFLAGS="$PHP_LDFLAGS" \
        ; \
        docker-php-source extract; \
        cd /usr/src/php; \
        gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
        debMultiarch="$(dpkg-architecture --query DEB_BUILD_MULTIARCH)"; \
        if [ ! -d /usr/include/curl ]; then \
                ln -sT "/usr/include/$debMultiarch/curl" /usr/local/include/curl; \
        fi; \
        ./configure \
                --build="$gnuArch" \
                --with-config-file-path="$PHP_INI_DIR" \
                --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
                                --enable-option-checking=fatal \
                                --with-mhash \
                                --with-pic \
                                --enable-ftp \
                --enable-mbstring \
                --enable-mysqlnd \
                --with-password-argon2 \
                --with-sodium=shared \
                --with-pdo-sqlite=/usr \
                --with-sqlite3=/usr \
                                --with-curl \
                --with-openssl \
                --with-readline \
                --with-zlib \
                                --with-pear \
                                $(test "$gnuArch" = 's390x-linux-gnu' && echo '--without-pcre-jit') \
                --with-libdir="lib/$debMultiarch" \
                                --disable-cgi \
                                --with-apxs2 \
        ; \
        make -j "$(nproc)"; \
        find -type f -name '*.a' -delete; \
        make install; \
        find \
                /usr/local \
                -type f \
                -perm '/0111' \
                -exec sh -euxc ' \
                        strip --strip-all "$@" || : \
                ' -- '{}' + \
        ; \
        make clean; \
        cp -v php.ini-* "$PHP_INI_DIR/"; \
        cd /; \
        docker-php-source delete; \
        apt-mark auto '.*' > /dev/null; \
        [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
        find /usr/local -type f -executable -exec ldd '{}' ';' \
                | awk '/=>/ { print $(NF-1) }' \
                | sort -u \
                | xargs -r dpkg-query --search \
                | cut -d: -f1 \
                | sort -u \
                | xargs -r apt-mark manual \
        ; \
        apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
        rm -rf /var/lib/apt/lists/*; \
        pecl update-channels; \
        rm -rf /tmp/pear ~/.pearrc; \
        php --version
COPY multi:ee8b9bb4e448c5d38508b40a8ace77d14cf000229390e687b6d467283c9826e6 in /usr/local/bin/
RUN docker-php-ext-enable sodium
ENTRYPOINT ["docker-php-entrypoint"]
STOPSIGNAL SIGWINCH
COPY file:e3123fcb6566efa979f945bfac1c94c854a559d7b82723e42118882a8ac4de66 in /usr/local/bin/
WORKDIR /var/www/html
EXPOSE 80
CMD ["apache2-foreground"]
RUN set -eux; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                ghostscript \
        ; \
        rm -rf /var/lib/apt/lists/*
RUN set -ex; \
        savedAptMark="$(apt-mark showmanual)"; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                libfreetype6-dev \
                libjpeg-dev \
                libmagickwand-dev \
                libpng-dev \
                libwebp-dev \
                libzip-dev \
        ; \
        docker-php-ext-configure gd \
                --with-freetype \
                --with-jpeg \
                --with-webp \
        ; \
        docker-php-ext-install -j "$(nproc)" \
                bcmath \
                exif \
                gd \
                mysqli \
                zip \
        ; \
        pecl install imagick-3.6.0; \
        docker-php-ext-enable imagick; \
        rm -r /tmp/pear; \
        out="$(php -r 'exit(0);')"; \
        [ -z "$out" ]; \
        err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
        [ -z "$err" ]; \
        extDir="$(php -r 'echo ini_get("extension_dir");')"; \
        [ -d "$extDir" ]; \
        apt-mark auto '.*' > /dev/null; \
        apt-mark manual $savedAptMark; \
        ldd "$extDir"/*.so \
                | awk '/=>/ { print $3 }' \
                | sort -u \
                | xargs -r dpkg-query -S \
                | cut -d: -f1 \
                | sort -u \
                | xargs -rt apt-mark manual; \
        apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
        rm -rf /var/lib/apt/lists/*; \
        ! {
    
     ldd "$extDir"/*.so | grep 'not found'; }; \
        err="$(php --version 3>&1 1>&2 2>&3)"; \
        [ -z "$err" ]
RUN set -eux; \
        docker-php-ext-enable opcache; \
        {
    
     \
                echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=2'; \
        echo 'opcache.fast_shutdown=1'; \
        } > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN {
    
     \
                echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
        echo 'display_errors = Off'; \
        echo 'display_startup_errors = Off'; \
        echo 'log_errors = On'; \
        echo 'error_log = /dev/stderr'; \
        echo 'log_errors_max_len = 1024'; \
        echo 'ignore_repeated_errors = On'; \
        echo 'ignore_repeated_source = Off'; \
        echo 'html_errors = Off'; \
        } > /usr/local/etc/php/conf.d/error-logging.ini
RUN set -eux; \
        a2enmod rewrite expires; \
        a2enmod remoteip; \
        {
    
     \
                echo 'RemoteIPHeader X-Forwarded-For'; \
        echo 'RemoteIPTrustedProxy 10.0.0.0/8'; \
        echo 'RemoteIPTrustedProxy 172.16.0.0/12'; \
        echo 'RemoteIPTrustedProxy 192.168.0.0/16'; \
        echo 'RemoteIPTrustedProxy 169.254.0.0/16'; \
        echo 'RemoteIPTrustedProxy 127.0.0.0/8'; \
        } > /etc/apache2/conf-available/remoteip.conf; \
        a2enconf remoteip; \
        find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
RUN set -eux; \
        version='5.8.2'; \
        sha1='c3b1b59553eafbf301c83b14c5eeae4cf1c86044'; \
        curl -o wordpress.tar.gz -fL "https://wordpress.org/wordpress-$version.tar.gz"; \
        echo "$sha1 *wordpress.tar.gz" | sha1sum -c -; \
        tar -xzf wordpress.tar.gz -C /usr/src/; \
        rm wordpress.tar.gz; \
        [ ! -e /usr/src/wordpress/.htaccess ]; \
        {
    
     \
                echo '# BEGIN WordPress'; \
        echo ''; \
        echo 'RewriteEngine On'; \
        echo 'RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]'; \
        echo 'RewriteBase /'; \
        echo 'RewriteRule ^index\.php$ - [L]'; \
        echo 'RewriteCond %{REQUEST_FILENAME} !-f'; \
        echo 'RewriteCond %{REQUEST_FILENAME} !-d'; \
        echo 'RewriteRule . /index.php [L]'; \
        echo ''; \
        echo '# END WordPress'; \
        } > /usr/src/wordpress/.htaccess; \
        chown -R www-data:www-data /usr/src/wordpress; \
        mkdir wp-content; \
        for dir in /usr/src/wordpress/wp-content/*/ cache; do \
                dir="$(basename "${dir%/}")"; \
        mkdir "wp-content/$dir"; \
        done; \
        chown -R www-data:www-data wp-content; \
        chmod -R 777 wp-content
VOLUME [/var/www/html]
COPY --chown=www-data:www-datafile:f95ddeaad9b50ddddf288560052a9de4f33fa6297ea70870e396f6d99c482b7a in /usr/src/wordpress/
COPY file:5be6bcc31206cb827f037769d89fd092037ed61a1e10d6cae7939a37055beb4c in /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

猜你喜欢

转载自blog.csdn.net/m0_46213587/article/details/130353048