簡體   English   中英

無法在 nginx /etc/nginx/conf.d/default.conf 中復制配置文件

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

無法將我的項目目錄中的配置文件復制到 /etc/nginx/conf.d/default.conf

源文件位置:/app/nginx.conf

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

目的地:/etc/nginx/conf.d/default.conf

docker 文件中的步驟:

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

嘗試評論第一個復制命令,它能夠復制構建並且很好。 當它能夠在應用程序目錄中找到構建時,為什么它無法找到也在同一目錄中的 nginix.conf 文件,做了一個 ls -la 並看到了 nginix.conf 文件。

TIA

如果源文件路徑是/app/nginix.conf則 docefile 應包含:

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

如果您從主機上的/app目錄運行docker build命令,那么您上面的 dockerfile 應該可以工作。

更新:

如果您希望node docker 鏡像的 /app/nginx.conf 文件出現在nginx:alpine鏡像中,那么您需要使用多階段docker 構建。

將您的dockerfile更改為

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

這會將/app/nginx.conf文件從node映像復制到nginx:alpine映像。

我在docker文件下面

從gitlab / gitlab-ce作為VCS WORKDIR / opt /運行git config --global http.ssl驗證錯誤RUN git clone --branch master --single-branch https://eamples.git

FROM ruby​​:2.3.0運行寶石安裝指南針運行寶石安裝sass

FROM節點:8作為BUILD COPY --from = VCS / opt / starreviewers / UI / / opt / starreviewers / UI / WORKDIR / opt / starreviewers / UI / RUN NPM緩存清理-強制RUN NPM安裝RUN NPM審核修復程序-強制運行npm install -g grunt-cli運行npm install bower RUN npm install karma grunt-karma RUN grunt --no-color clean --force RUN grunt --no-color build --force

從nginx:1.13.3-alpine RUN rm -rf / usr / share / nginx / html / * COPY --from = BUILD / opt / starreviewers / UI / dist / / usr / share / nginx / html / RUN ls -lrt / usr / share / nginx / html / CMD [“ nginx”,“-g”,“守護程序關閉”;]

在構建映像時,它將所有文件從/ opt / starreviewers / UI / dist /復制到/ usr / share / nginx / html /,並使用ls命令打印

但是當我運行該映像時,/ usr / share / nginx / html /中只有默認文件,不知道為什么/ usr / share / nginx / html /為空運行時

如果有人還在為此苦苦掙扎......

將 WORKDIR 從 app 更改為 builddir 有效!

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;"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM