Unable to COPY config file in nginix /etc/nginx/conf.d/default.conf

15,895

If the source file path is /app/nginix.conf then dockefile should contain:

COPY /app/nginx.conf /etc/nginx/conf.d/default.conf

If you're running docker build command from /app directory on your host then your above dockerfile should work.

Update:

If you're expecting /app/nginx.conf file of node docker image to present in nginx:alpine image then you need to use multi-stage docker builds.

Change your dockerfile to

FROM node as build
WORKDIR /app
COPY package json files 
RUN npm build

FROM nginx:alpine 
COPY --from=build /app/nginx.conf /etc/nginx/conf.d/default.conf

This will copy /app/nginx.conf file from node image to nginx:alpine image.

Share:
15,895
Kashyap
Author by

Kashyap

Updated on June 22, 2022

Comments

  • Kashyap
    Kashyap almost 2 years

    Unable to Copy config file in my project dir to /etc/nginx/conf.d/default.conf

    source file location: /app/nginix.conf

    COPY nginx.conf /etc/nginx/conf.d/default.conf

    destination : /etc/nginx/conf.d/default.conf

    Steps in docker file :

    Tried the multi stage build:
    
    - FROM node:8.9.0 as buid
    - WORKDIR /app
    - COPY package.json package-lock.json ./
    - RUN npm install
    - COPY . ./
    - RUN npm run build
    
    
    - FROM nginx:alpine
    - RUN mkdir -p /var/www/html/client
    - COPY --from=buid /app/nginix.conf /etc/nginx/conf.d/default.conf
    - COPY --from=buid /app/build/ /var/www/html/client
    

    Tried commenting the first copy command, and it was able to copy the build and it was good. when it is able to find the build in the app dir why is it not able to find the nginix.conf file which is also in the same dir, did a ls -la and saw the nginix.conf file.

    TIA

    • David Maze
      David Maze almost 5 years
      On your local system, is nginx.conf in the same directory as your Dockerfile?
    • Kashyap
      Kashyap almost 5 years
      yes, Docker file and nginix.conf both are in the same directory.
  • Kashyap
    Kashyap almost 5 years
    I tried the same : COPY failed: stat /var/lib/docker/tmp/docker-builder-number/app/nginx.conf: no such file or directory. After reaching this point: FROM nginix:alpine the dir is changing am not able to figure that out.
  • mchawre
    mchawre almost 5 years
    Can you explain more, what output you got.
  • Kashyap
    Kashyap almost 5 years
    - FROM node - WORKDIR /app - COPY package json files - RUN npn build I tried pwd and ls -la, I could see all my project files and my config file as well FROM nginix:alpine not sure whats going on after this point.
  • mchawre
    mchawre almost 5 years
    Does that nginx.conf file gets created in FROM node image in /app folder which you want that in FROM nginx:alpine image.
  • Kashyap
    Kashyap almost 5 years
    I want that from /app folder, but when am doing FROM nginx:alpine, the root is getting changed and not able to find the nginix.conf file.
  • mchawre
    mchawre almost 5 years
    Updated my answer.
  • mchawre
    mchawre almost 5 years
    let me know if it helped or I mis-interpretted what you are asking for.
  • Kashyap
    Kashyap almost 5 years
    Tried the multi stage build: - FROM node:8.9.0 as buid - WORKDIR /app - COPY package.json package-lock.json ./ - RUN npm install - COPY . ./ - RUN npm run build - FROM nginx:alpine - RUN mkdir -p /var/www/html/client - COPY --from=buid /app/nginx.conf /etc/nginx/conf.d/default.conf - COPY --from=buid /app/build/ /var/www/html/client
  • Kashyap
    Kashyap almost 5 years
    Modified the question please have a look