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
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.
If somebody is still struggling with this....
changing the WORKDIR from app to builddir worked!
FROM node:alpine as builder
WORKDIR '/builddir'
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /builddir/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]