1

I'm unable to get docker working on OSX Big Sur with my React application. The below files were already set up and I've spent a good portion of my day looking for answers on S/O like Docker COPY no such file or directory & COPY failed: stat /var/lib/docker/tmp/docker-builder076499369/files/nginx.conf: no such file or directory.

However, I am still unable to get it to work as shown by the terminal error displayed below.

I am running docker build .

This is my file structure:

ProjectName
//all the usual stuff
  |_src
    |_ components/
    |_ App.js
.dockerignore
.env
.docker-compose
Dockerfile
nginx.conf

running this command always returns: COPY failed: stat /var/lib/docker/tmp/docker-builder989058242/build: no such file or directory

Dockerfile

# The NGINX based on LINUX Alpine distribution is the target webserver image
FROM nginx:1.15.8-alpine

# Remove all previous default files on webroot 
RUN rm -rf /usr/share/nginx/html/*

COPY ./nginx.conf /etc/nginx/nginx.conf

COPY ./build/ /usr/share/nginx/html/

# Open the port 80 of the Image (the webserver) to the world
EXPOSE 80

# run NGINX
CMD ["nginx", "-g", "daemon off;"]

docker-compose.yml

version: '2'
services:
    webapp:
        build: ./
        container_name: react_front_container
        image: react_front
        ports:
            - '30301:3000'
        env_file:
            - .env
        networks:
            - dockerdatabase
        external_links:
            - 'react_back_container:api_url'
networks:
    dockerdatabase:
        external: true

nginx.conf

  worker_processes  1;

    events {
      worker_connections  1024;
    }

    http {
      server {
        listen 80;
        server_name  localhost;

        root   /usr/share/nginx/html;
        index  index.html index.htm;
        include /etc/nginx/mime.types;

        gzip on;
        gzip_min_length 1000;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        location / {
          try_files $uri $uri/ /index.html;
        }
      }
    }

.dockerignore

node_modules
npm-debug.log

When I run docker build, I get the following error.

Terminal Output

 docker build .                              
Sending build context to Docker daemon  21.97MB
Step 1/6 : FROM nginx:1.15.8-alpine
 ---> b411e34b4606
Step 2/6 : RUN rm -rf /usr/share/nginx/html/*
 ---> Using cache
 ---> c1cc0c4628ee
Step 3/6 : COPY ./nginx.conf /etc/nginx/nginx.conf
 ---> b86369d90215
Step 4/6 : COPY ./build/ /usr/share/nginx/html/
COPY failed: stat /var/lib/docker/tmp/docker-builder989058242/build: no such file or directory

Sorry for the long post, but I am hoping a good explanation will help me understand what I am not doing correctly. As a UX dev, I'm not very familiar with dealing with DevOps. Where am I going wrong? Thanks in advance.

Noble Polygon
  • 796
  • 11
  • 36
  • 1
    Do you have a local `build` directory before you start this sequence; do you need to `npm run build` or something similar first? It's also common to combine these two steps (build the application, build the deployment image) into a single multi-stage build. – David Maze Nov 27 '20 at 15:37
  • @DavidMaze I feel a bit silly but you're right. I ran ```npm run build``` and I finally got a success message back. ```Successfully built f320e8178496``` please add your solution as the correct answer and thank you for teaching me something new. – Noble Polygon Nov 27 '20 at 16:09

0 Answers0