How to fix FileNotFoundError in docker-compose

  docker, docker-compose, node.js, npm

I am taking a course on docker and it seems there is an issue with the docker build of the sample backend node app.

frontend dockerfile:

FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000 
CMD ["npm", "start"]

backend dockerfile:

FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . . 
EXPOSE 3001 
USER app
CMD ["npm", "start"]

docker-compose.yml:

version: "3.8"

services:
  frontend:
    depends_on: 
      - backend
    build: ./frontend
    ports:
      - 3000:3000

  backend: 
    depends_on: 
      - db
    build: ./backend
    ports: 
      - 3001:3001
    environment: 
      DB_URL: mongodb://db/vidly
    command: ./docker-entrypoint.sh

  db:
    image: mongo:4.0-xenial
    ports:
      - 27017:27017
    volumes:
      - vidly:/data/db

volumes:
  vidly:

Tracback:

Building backend
Sending build context to Docker daemon  291.3kB
Step 1/9 : FROM node:14.16.0-alpine3.13
14.16.0-alpine3.13: Pulling from library/node
ca3cd42a7c95: Pull complete 
cf8dc363e30f: Pull complete 
074ae49463c4: Pull complete 
48fd78e4b532: Pull complete 
Digest: sha256:2c51dc462a02f15621e7486774d36d048a27225d581374b002b8477a79a59b4b
Status: Downloaded newer image for node:14.16.0-alpine3.13
 ---> 50bfd284aa0d
Step 2/9 : RUN addgroup app && adduser -S -G app app
 ---> Running in 4183bada01d2
Removing intermediate container 4183bada01d2
 ---> 0c55d313489a
Step 3/9 : WORKDIR /app
 ---> Running in e6da0a502c0c
Removing intermediate container e6da0a502c0c
 ---> c62eee1e61e1
Step 4/9 : COPY package*.json ./
 ---> caad8596ddd4
Step 5/9 : RUN npm install
 ---> Running in 5d2f331053db

> [email protected] postinstall /app/node_modules/nodemon
> node bin/postinstall || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 770 packages from 462 contributors and audited 771 packages in 10.856s

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

found 90 vulnerabilities (61 moderate, 28 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 5d2f331053db
 ---> 89123dc063c8
Step 6/9 : COPY . .
 ---> 74c3d17d99a8
Step 7/9 : EXPOSE 3001
 ---> Running in db775adf83f0
Removing intermediate container db775adf83f0
 ---> 82e0d9220d54
Step 8/9 : USER app
 ---> Running in 95d1419578ac
Removing intermediate container 95d1419578ac
 ---> ffb4ca92826e
Step 9/9 : CMD ["npm", "start"]
 ---> Running in d1b88a01f889
Removing intermediate container d1b88a01f889
 ---> 418d04e16184
Successfully built 418d04e16184
Successfully tagged vidly_backend:latest
Traceback (most recent call last):
  File "docker-compose", line 3, in <module>
  File "compose/cli/main.py", line 81, in main
  File "compose/cli/main.py", line 203, in perform_command
  File "compose/metrics/decorator.py", line 18, in wrapper
  File "compose/cli/main.py", line 1186, in up
  File "compose/cli/main.py", line 1182, in up
  File "compose/project.py", line 664, in up
  File "compose/service.py", line 364, in ensure_image_exists
  File "compose/service.py", line 1133, in build
  File "compose/service.py", line 1948, in build
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpafoiltwd'
[39279] Failed to execute script docker-compose

I am thinking /tmp/tmpafoiltwd may be on the host machine (?) and there is a permissions conflict (though it isn’t a permissions error). I am confused on the next step to take. Any direction would be appreciated 🙂

EDIT:
If I move USER app up to the 3rd line I get a permissions error:

FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . . 
EXPOSE 3001 
CMD ["npm", "start"]

Traceback:

npm WARN checkPermissions Missing write access to /app
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/app'
npm ERR!  [Error: EACCES: permission denied, access '/app'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/app'
npm ERR! }

Source: Docker Questions

LEAVE A COMMENT