Docker的构build:是从一个层次的内容保持下一个?

我正在尝试Dockerize PyroCMS ,这就是我的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 

这是一个在制品,所以不要打扰优化等等,因为我现在不关心它。

为了构build镜像,我正在运行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 

当然,这使得构build失败,因为文件artisan已经不存在了。

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

我只是把reynierpm/docker-centos7-supervisord:latest我的机器上的reynierpm/docker-centos7-supervisord:latest映像,并且该映像中的/data位置是一个卷。

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

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

为了解决这个问题,请确保将ADD或COPY文件添加到您正在使用的基本映像中不是卷的位置。