docker-engine 17.05.0~ce-0~ubuntu-xenial を使用して、この Dockerfile をビルドしています。
FROM wordpress:apache as codebase
FROM wordpress:cli as cli
COPY --from=codebase /usr/src/wordpress /var/www/html
# Create a config
RUN wp --path=/var/www/html config create --dbname=dbname --dbuser=dbuser --skip-check \
&& ls /var/www/html/wp-config.php
RUN ls /var/www/html/wp-config.php
しかし、出力は期待どおりではありません。wordpress:apache からコピーしたコードは /var/www/html に正しく追加されていますが、wp-config.php は実際のビルド ステップ中にのみ存在し、結果のイメージには存在しません。ここで何が間違っているのかわかりません。ビルドすると、次のように終了します。
$ docker build -t wptest . --no-cache
Sending build context to Docker daemon 2.048kB
Step 1/5 : FROM wordpress:apache as codebase
---> 1d3cc82944da
Step 2/5 : FROM wordpress:cli as cli
---> ee57985dea6f
Step 3/5 : COPY --from=codebase /usr/src/wordpress /var/www/html
---> e10d62f3d7bc
Removing intermediate container e09a35e05108
Step 4/5 : RUN wp --path=/var/www/html config create --dbname=dbname --dbuser=dbuser --skip-check && ls /var/www/html/wp-config.php
---> Running in 8b2b3e98163e
Success: Generated 'wp-config.php' file.
/var/www/html/wp-config.php
---> b0934cfed497
Removing intermediate container 8b2b3e98163e
Step 5/5 : RUN ls /var/www/html/wp-config.php
---> Running in cda6a5c16fb5
ls: /var/www/html/wp-config.php: No such file or directory
The command '/bin/sh -c ls /var/www/html/wp-config.php' returned a non-zero code: 1
最初の RUN で作成された wp-config.php が次のステップで利用できないのに、COPY コマンドでそこに入れられたデータがそこに残るのはなぜですか?
(私が何を達成しようとしているのか疑問に思っている場合は、これは単なる MCVE です。)