Unable to COPY config file in nginix /etc/nginx/conf.d/default.conf
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.
Kashyap
Updated on June 22, 2022Comments
-
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 almost 5 yearsOn your local system, is
nginx.conf
in the same directory as yourDockerfile
? -
Kashyap almost 5 yearsyes, Docker file and nginix.conf both are in the same directory.
-
-
Kashyap almost 5 yearsI 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 almost 5 yearsCan you explain more, what output you got.
-
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 almost 5 yearsDoes that nginx.conf file gets created in FROM node image in /app folder which you want that in FROM nginx:alpine image.
-
Kashyap almost 5 yearsI 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 almost 5 yearsUpdated my answer.
-
mchawre almost 5 yearslet me know if it helped or I mis-interpretted what you are asking for.
-
Kashyap almost 5 yearsTried 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 almost 5 yearsModified the question please have a look