gpt4 book ai didi

docker - Docker构建:来自一层的内容是否保留在下一层?

转载 作者:行者123 更新时间:2023-12-02 20:49:46 31 4
gpt4 key购买 nike

我正在尝试对PyroCMS进行Docker化,这就是我的Dockerfile的样子:

FROM reynierpm/docker-centos7-supervisord:latest
ENV TERM=xterm \
PATH="/root/.composer/vendor/bin:${PATH}" \
COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_ALLOW_XDEBUG=1 \
COMPOSER_DISABLE_XDEBUG_WARN=1 \
COMPOSER_HOME="/root/.composer" \
COMPOSER_CACHE_DIR="/root/.composer/cache"

RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
https://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum install -y \
yum-utils \
git \
zip \
unzip \
wget \
nano \
php71-php-fpm \
php71-php-cli \
php71-php-common \
php71-php-gd \
php71-php-intl \
php71-php-json \
php71-php-mbstring \
php71-php-mcrypt \
php71-php-mysqlnd \
php71-php-pdo \
php71-php-pear \
php71-php-xml \
php71-php-pecl-xdebug \
php71-pecl-apcu \
php71-php-pecl-apfd \
php71-php-pecl-memcache \
php71-php-pecl-memcached \
php71-php-pecl-mongodb \
php71-php-pecl-redis \
php71-php-pecl-request \
php71-php-pecl-uploadprogress \
php71-php-pecl-xattr \
php71-php-pecl-zip && \
yum clean all && rm -rf /tmp/yum*
RUN ln -sfF /opt/remi/php71/enable /etc/profile.d/php71-paths.sh && \
ln -sfF /opt/remi/php71/root/usr/bin/{pear,pecl,phar,php,php-cgi,phpize} /usr/local/bin/. && \
mv -f /etc/opt/remi/php71/php.ini /etc/php.ini && \
ln -sfF /etc/php.ini /etc/opt/remi/php71/php.ini && \
rm -rf /etc/php.d && \
mv /etc/opt/remi/php71/php.d /etc/. && \
ln -sfF /etc/php.d /etc/opt/remi/php71/php.d

RUN /bin/sh -c "mkdir -p /data/www" && \
/bin/sh -c "mkdir -p /data/php/{tmp,sessions,xdebug,logs,uploads}" && \
rm -rf /data/www/*
COPY container-files /
WORKDIR /data/www
RUN sh /usr/local/bin/composer-install.sh
RUN git clone --branch 3.2 https://github.com/pyrocms/pyrocms.git .
COPY .env .
RUN pwd && ls -la
RUN php artisan install --ready
RUN chmod +x /config/bootstrap.sh
EXPOSE 9005

这是一个WIP,所以不要理会优化之类的东西,因为我现在不在乎它。

为了构建图像,我正在运行 docker build -t reynierpm/pyrocms .,它将平稳进行直到到达此步骤:
RUN php artisan install --ready

失败并显示以下错误:
Step 14/16 : RUN php artisan install --ready
---> Running in ffbddd585ef1
Could not open input file: artisan
The command '/bin/sh -c php artisan install --ready' returned a non-zero code: 1

我不确定自己在做什么错,但这是到目前为止的事情:
  • WORKDIR /data/www将从现在开始将所有工作保留在/data/www上,除非我将其更改为我在任何时候都没有做的其他目录
  • RUN git clone --branch 3.2 https://github.com/pyrocms/pyrocms.git .正确克隆了存储库分支,因为在命令显示以下输出后立即执行了ls -la:
    drwxr-xr-x 16 root root 4096 Jan 26 16:50 .
    drwxr-xr-x 3 root root 4096 Jan 26 16:50 ..
    drwxr-xr-x 8 root root 4096 Jan 26 16:50 .git
    -rw-r--r-- 1 root root 12 Jan 26 16:50 .gitattributes
    -rw-r--r-- 1 root root 97 Jan 26 16:50 .gitignore
    -rw-r--r-- 1 root root 2254 Jan 26 16:50 CONTRIBUTING.md
    -rwxr-xr-x 1 root root 556 Jan 26 16:50 Gulpfile.js
    -rw-r--r-- 1 root root 1088 Jan 26 16:50 LICENSE.md
    -rw-r--r-- 1 root root 236 Jan 26 16:50 README.md
    drwxr-xr-x 2 root root 4096 Jan 26 16:50 addons
    drwxr-xr-x 3 root root 4096 Jan 26 16:50 app
    -rwxr-xr-x 1 root root 1646 Jan 26 16:50 artisan
    drwxr-xr-x 3 root root 4096 Jan 26 16:50 bootstrap
    -rw-r--r-- 1 root root 1525 Jan 26 16:50 build.xml
    -rw-r--r-- 1 root root 3708 Jan 26 16:50 composer.json
    drwxr-xr-x 2 root root 4096 Jan 26 16:50 config
    drwxr-xr-x 2 root root 4096 Jan 26 16:50 core
    drwxr-xr-x 5 root root 4096 Jan 26 16:50 database
    drwxr-xr-x 3 root root 4096 Jan 26 16:50 docs
    -rwxr-xr-x 1 root root 400 Jan 26 16:50 package.json
    -rwxr-xr-x 1 root root 1397 Jan 26 16:50 phpunit.xml
    drwxr-xr-x 5 root root 4096 Jan 26 16:50 public
    drwxr-xr-x 6 root root 4096 Jan 26 16:50 resources
    drwxr-xr-x 2 root root 4096 Jan 26 16:50 routes
    -rwxr-xr-x 1 root root 560 Jan 26 16:50 server.php
    drwxr-xr-x 8 root root 4096 Jan 26 16:50 storage
    drwxr-xr-x 2 root root 4096 Jan 26 16:50 tests
    drwxr-xr-x 3 root root 4096 Jan 26 16:50 tmp
  • COPY .env .将文件.env复制到/data/www(但是如果语法错误,已经使用COPY .env /data/www/.env尝试过)

  • 运行上述步骤后,我应该以克隆的内容以及 .dev结尾,但这很奇怪,因为我仅以以下形式结束:
    total 12
    drwxr-xr-x 2 root root 4096 Jan 26 16:54 .
    drwxr-xr-x 3 root root 4096 Jan 26 16:54 ..
    -rw-rw-r-- 1 root root 337 Jan 26 15:39 .env

    当然,由于文件 artisan不再存在,因此这会使构建失败。

    为什么?文件不应该保留在层之间吗?有任何想法吗?

    最佳答案

    我只是在机器上拉了reynierpm/docker-centos7-supervisord:latest图像,该图像中的/data位置是一个卷。

    $ docker inspect reynierpm/docker-centos7-supervisord:latest
    ...
    "Volumes": {
    "/data": {}
    },
    ...

    构建中的每个步骤都作为容器运行。由于 /data是图像指定的卷,因此每个步骤在/ data处都会有一个新的空白匿名卷。构建步骤完成后,对该容器的写时复制系统的更改将作为下一层提交。由于对 /data的任何更改都在卷中而不在COW文件系统中,因此它们不包含在提交中。

    要解决此问题,请确保将文件添加或复制到您使用的基础镜像中不是卷的位置。

    关于docker - Docker构建:来自一层的内容是否保留在下一层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41879020/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com