I have a multistage Dockerfile
which copies some parts from the first image to the second one, which always fails with this line
COPY --from=react-builder /app/build /var/www
with this error
Step 17/22 : COPY --from=react-builder /app/build /var/www
COPY failed: stat /mnt/data/docker/overlay2/901e2feb2323e7fc6d9de0f3e64e84d16d1e935e198bf19f15021af0eb6134d6/merged/app/build: no such file or directory
Here is the Dockerfile
FROM node:10-slim AS react-builder
ARG REACT_APP_ENV
ENV REACT_APP_ENV $REACT_APP_ENV
WORKDIR app
COPY . .
RUN cat /app/.env | grep = | sort | sed -e 's|REACT_APP_([a-zA-Z_]*)=(.*)|REACT_APP_1=NGINX_REPLACE_1|' > /app/.env.local
RUN npm config set registry=https://npm.company.com
RUN npm config set "strict-ssl" false
RUN npm install
RUN npm build
FROM nginx:1.15
COPY nginx.conf.template /etc/nginx/conf.d/nginx.conf.template
COPY gcp-deploy/htpasswd /etc/nginx/htpasswd
COPY --from=react-builder /app/.env.local /etc/nginx/conf.d/
RUN NGINX_SUB_FILTER=$(cat /etc/nginx/conf.d/.env.local | grep '=' | sort | sed -e 's/REACT_APP_([a-zA-Z_]*)=(.*)/sub_filter "NGINX_REPLACE_1" "${1}";/') && cat /etc/nginx/conf.d/nginx.conf.template | sed -e "s|LOCATION_SUB_FILTER|$(echo $NGINX_SUB_FILTER)|" | sed -u 's|}"; |}";ntt|g' > /etc/nginx/conf.d/default.conf.template
COPY --from=react-builder /app/build /var/www
# This is a hack around the envsubst nginx config. Because we have `$uri` set
# up, it would replace this as well. Now we just reset it to its original value.
ENV uri $uri
# Default config
ENV REST_URI " https://whatever.wherever.com/"
ENV PORT 80
ENV SERVER_NAME _
CMD ["sh", "-c", "envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
Expected behavior
Running docker build .
simply builds the image without issues
Actual behavior
Build always fails with the same COPY --from
statement. There is a second COPY --from
command which always passes. If i switch the order I still get the same error:
Step 17/22 : COPY --from=react-builder /app/build /var/www
COPY failed: stat /mnt/data/docker/overlay2/901e2feb2323e7fc6d9de0f3e64e84d16d1e935e198bf19f15021af0eb6134d6/merged/app/build: no such file or directory
Output of docker version
:
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.39 (downgraded from 1.40)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:25:41 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:19:08 2018
OS/Arch: linux/amd64
Experimental: false
Output of docker info
:
Client:
Debug Mode: false
Server:
Containers: 17
Running: 1
Paused: 0
Stopped: 16
Images: 374
Server Version: 18.09.0
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1062.9.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.701GiB
Name: devs0211
ID: 25FQ:7G3D:T46W:4DTJ:VV4A:V7JG:DZ53:C2E4:O7JN:WUP6:XWPA:3FX4
Docker Root Dir: /mnt/data/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://docker.company.com/
Live Restore Enabled: true
Product License: Community Engine
Some more details of the build process incl. an additional ls -ls /app
$ docker build . --no-cache
[sudo] password for sc146082:
Your password will expire in 4 day(s).
Sending build context to Docker daemon 3.561MB
Step 1/23 : FROM node:10-slim as react-builder
---> 92eff963766f
Step 2/23 : ARG REACT_APP_ENV
---> Running in 13e997164e2c
Removing intermediate container 13e997164e2c
---> 8edcfa0931a8
Step 3/23 : ENV REACT_APP_ENV $REACT_APP_ENV
---> Running in 17fa11f08e3e
Removing intermediate container 17fa11f08e3e
---> a906714bef73
Step 4/23 : WORKDIR /app
---> Running in cbc94fc1faa8
Removing intermediate container cbc94fc1faa8
---> 10eaff3f4774
Step 5/23 : COPY . .
---> 567cfa8797d9
Step 6/23 : RUN cat /app/.env | grep = | sort | sed -e 's|REACT_APP_([a-zA-Z_]*)=(.*)|REACT_APP_1=NGINX_REPLACE_1|' > /app/.env.local
---> Running in c28d9688f19e
Removing intermediate container c28d9688f19e
---> 65dd918e5162
Step 7/23 : RUN npm config set registry=https://npm.company.com
---> Running in f83b8b73b4e8
Removing intermediate container f83b8b73b4e8
---> d36d51e3cabb
Step 8/23 : RUN npm config set "strict-ssl" false
---> Running in 1f65e71e350b
Removing intermediate container 1f65e71e350b
---> d297ff074f44
Step 9/23 : RUN npm install
---> Running in 09a445362f73
....
added 1696 packages from 978 contributors in 42.078s
55 packages are looking for funding
run `npm fund` for details
Removing intermediate container 09a445362f73
---> c30a48bda924
Step 10/23 : RUN npm build
---> Running in be3f6a0a64ea
npm WARN build `npm build` called with no arguments. Did you mean to `npm run-script build`?
Removing intermediate container be3f6a0a64ea
---> 14a5a88aeeb1
Step 11/23 : RUN pwd
---> Running in 1b7603116844
/app
Removing intermediate container 1b7603116844
---> 0579c1f467a8
Step 12/23 : RUN ls -ls /app
---> Running in fd4479923203
total 1240
4 -rw-r--r--. 1 root root 1406 Feb 5 11:37 Dockerfile
4 -rw-r--r--. 1 root root 504 Feb 4 14:10 Jenkinsfile
4 -rw-r--r--. 1 root root 1057 Feb 4 14:09 README.md
0 drwxr-xr-x. 2 root root 83 Feb 4 14:09 gcp-deploy
4 -rw-r--r--. 1 root root 827 Feb 4 14:09 nginx.conf.template
60 drwxr-xr-x. 1150 root root 36864 Feb 5 11:37 node_modules
628 -rw-r--r--. 1 root root 639799 Feb 5 11:37 package-lock.json
4 -rw-r--r--. 1 root root 2821 Feb 4 14:09 package.json
12 -rw-r--r--. 1 root root 9106 Feb 4 14:18 pom.xml
0 drwxr-xr-x. 2 root root 64 Feb 4 14:09 public
4 -rw-r--r--. 1 root root 591 Feb 4 14:09 sonar-project.properties
4 drwxr-xr-x. 15 root root 4096 Feb 4 14:09 src
0 drwxr-xr-x. 2 root root 28 Feb 4 14:10 target
4 -rw-r--r--. 1 root root 486 Feb 4 14:09 tsconfig.json
508 -rw-r--r--. 1 root root 517508 Feb 4 14:09 yarn.lock
Removing intermediate container fd4479923203
---> e3329a5200cd
Step 13/23 : FROM nginx:1.15
---> 53f3fd8007f7
Step 14/23 : COPY nginx.conf.template /etc/nginx/conf.d/nginx.conf.template
---> c6ddc33a47e7
Step 15/23 : COPY gcp-deploy/htpasswd /etc/nginx/htpasswd
---> db3d7c99cea0
Step 16/23 : COPY --from=react-builder /app/.env.local /etc/nginx/conf.d/
---> 973f6987ab00
Step 17/23 : RUN NGINX_SUB_FILTER=$(cat /etc/nginx/conf.d/.env.local | grep '=' | sort | sed -e 's/REACT_APP_([a-zA-Z_]*)=(.*)/sub_filter "NGINX_REPLACE_1" "${1}";/') && cat /etc/nginx/conf.d/nginx.conf.template | sed -e "s|LOCATION_SUB_FILTER|$(echo $NGINX_SUB_FILTER)|" | sed -u 's|}"; |}";ntt|g' > /etc/nginx/conf.d/default.conf.template
---> Running in a1eb5fdc7a02
Removing intermediate container a1eb5fdc7a02
---> ee3041f221df
Step 18/23 : COPY --from=react-builder /app/build /var/www
COPY failed: stat /mnt/data/docker/overlay2/7a85db99ff921b8588b566624634cc64c864f0e7db46c6540d09517662f7335a/merged/app/build: no such file or directory
and I can confirm that /mnt/data/docker/overlay2/7a85db99ff921b8588b566624634cc64c864f0e7db46c6540d09517662f7335a
does not exists
2
Answers
Apparently when running
RUN npm build
it does not happen what's expected - no compilation? - and thus there is no/app/build
directory. However if runningRUN npm run-script build
the compilation works fineTherefore also
COPY --from=react-builder /app/build /var/www
works fine.The error is clear that the path
/app/build
does not exist in thereact-builder
layer.What you can do to fix the problem is updating
WORKDIR app
toWORKDIR /app
like this:The problem is
WORKDIR app
is not the same asWORKDIR /app
so when you are executing theRUN npm build
, the generatedbuild
folder will not be saved in your expected/app/build
and hence the error.