Soteri
Soteri

Reputation: 347

Docker: Couldn't find copied file in container

What am I doing wrong?

I want to copy a file called default.conf to my container.

For that I have a dockerfile with COPY default.conf /opt/default.conf

The default.conf file is in the same directory like my dockerfile

When I execute the dockerfile it says:

Step 3/9 : COPY default.conf /opt/default.conf

---> 6529590ff51e

BUT when I go into the container with docker exec -it [container-id] /bin/sh

There is no default.conf

Dockerfile:

### STAGE 1: Build ###
FROM node:alpine AS build
WORKDIR /usr/src/app
COPY default.conf /opt/default.conf
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:alpine
COPY --from=build /usr/src/app/dist/proj /usr/share/nginx/html

My docker build:

docker build --rm -t test-application90:latest 

My docker build output:

Sending build context to Docker daemon  534.9MB
Step 1/9 : FROM node:alpine AS build
 ---> b7dc3fe8d4f8
Step 2/9 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 7694e6cef2f1
Step 3/9 : COPY default.conf /opt/
 ---> b8b59d09f29b
Step 4/9 : COPY package.json ./
 ---> d98bdcc549fa
Step 5/9 : RUN npm install
 ---> Running in 59b2f606a39c
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

> [email protected] postinstall /usr/src/app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> [email protected] postinstall /usr/src/app/node_modules/karma/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> @angular/[email protected] postinstall /usr/src/app/node_modules/@angular/cli
> node ./bin/postinstall/script.js

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/karma/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/abbrev):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/abbrev' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.abbrev.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/ansi-regex):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/ansi-regex' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.ansi-regex.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/aproba):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/aproba' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.aproba.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/balanced-match):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/balanced-match' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.balanced-match.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/chownr):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/chownr' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.chownr.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/code-point-at):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/code-point-at' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.code-point-at.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/concat-map):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/concat-map' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.concat-map.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/console-control-strings):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/console-control-strings' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.console-control-strings.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/core-util-is):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/core-util-is' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.core-util-is.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/deep-extend):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/deep-extend' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.deep-extend.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/delegates):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/delegates' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.delegates.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/detect-libc):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/detect-libc' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.detect-libc.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/fs.realpath):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/fs.realpath' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.fs.realpath.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/has-unicode):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/has-unicode' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.has-unicode.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/inherits):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/inherits' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.inherits.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/karma/node_modules/fsevents/node_modules/ini):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/ini' -> '/usr/src/app/node_modules/karma/node_modules/fsevents/node_modules/.ini.DELETE'

added 1340 packages from 1102 contributors and audited 17568 packages in 33.895s

32 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Removing intermediate container 59b2f606a39c
 ---> bacc44946554
Step 6/9 : COPY . .
 ---> cbf30a550904
Step 7/9 : RUN npm run build
 ---> Running in 451c06e9bb0a

> [email protected] build /usr/src/app
> ng build


chunk {main} main.js, main.js.map (main) 104 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 165 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 597 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 182 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.36 MB [initial] [rendered]
Date: 2020-02-21T13:05:54.311Z - Hash: cb71ed20199eb4ef3fee - Time: 8788ms
Removing intermediate container 451c06e9bb0a
 ---> 6a44a01d73f6
Step 8/9 : FROM nginx:alpine
 ---> 48c8a7c47625
Step 9/9 : COPY --from=build /usr/src/app/dist/proj /usr/share/nginx/html
 ---> Using cache
 ---> 387d470fb408
Successfully built 387d470fb408
Successfully tagged test-application90:latest

My docker run:

docker run --rm -d -p 90:80/tcp test-application90:latest

My docker run output:

be1814bc7cd89376e0a8477026f4b6e62dfe136fd1afd7eb3631a003fd95eb74

My Container listing with docker ps:

be1814bc7cd8        test-application90:latest     "nginx -g 'daemon of…"   1 second ago        Up Less than a second   0.0.0.0:90->80/tcp     admiring_mcclintock

My docker exec:

docker exec -it be1814bc7cd8 /bin/sh

Upvotes: 0

Views: 219

Answers (1)

BMitch
BMitch

Reputation: 263617

You have a multi-stage build. The file is copied in during the build of the first stage, and the second stage does not copy that file into the final image, so it's not expected to be there. If you wanted the file in the nginx stage only, you would copy it in that stage:

### STAGE 1: Build ###
FROM node:alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:alpine
COPY default.conf /opt/default.conf
COPY --from=build /usr/src/app/dist/proj /usr/share/nginx/html

Or if you want the file in the first stage and second stage, you can copy it from the first to the second stage:

### STAGE 1: Build ###
FROM node:alpine AS build
WORKDIR /usr/src/app
COPY default.conf /opt/default.conf
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:alpine
COPY --from=build /usr/src/app/dist/proj /usr/share/nginx/html
COPY --from=build /opt/default.conf /opt/default.conf

Upvotes: 1

Related Questions