我正在使用多阶段构建来编译react应用程序。在我使用nginx图像暴露到端口80之后,我主要使用基本节点图像。
我尝试将构建文件从builder stage复制到/usr/share/nginx/html文件夹,但什么也得不到。
单独构建映像它是有效的,使用docker-compose不会做任何事情。
我试图在docker repo上打开一个问题,但被关闭了,因此当podman(也就是使用moby引擎)工作良好时,在moby引擎上打开也不是一个选项,除了作为not sudoers生成命令的compose和在节点映像下载上的构建失败。
FROM node:slim as build
WORKDIR /usr/app
COPY package.json .
COPY public public
COPY src src
RUN npm install
RUN npm run build
COPY build .
RUN rm -rf src
RUN rm -rf build
FROM nginx:latest
COPY --from=build /usr/app /usr/share/nginx/html
# RUN chown www-data:www-data ./usr/share/nginx/html/*
EXPOSE 80在ls命令中,我看到了构建,但当我尝试连接到本地主机a时,得到了禁止的错误,而当我试图访问index.html时,我得到了404。
我使用bash进入html文件夹,并使用namei -l进行验证。而且根本没有文件。
我能做错什么呢?我已经搜索了一大堆问题,但没有得到答案或任何方向,除了添加要复制的文件夹的斜杠的事实。
目前我使用的是RHEL。因此,需要sudoers权限才能运行docker命令。也许这就是问题所在?在podman-compose上,我需要生成一个sudo docker-compose build命令,它以非root用户身份运行另一个build命令。
因此,这不会发生在docker-ce上。
发布于 2020-07-12 15:36:05
首先,确保在文件nginx.conf中有一个正确的nginx配置。例如:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}其次,没有必要运行以下代码行:
COPY build . # you should call directly the build folder, because there isn't any other files of build stage
RUN rm -rf src #after finish build step, this image will no longer exist.
RUN rm -rf build
RUN ls最后,Dockerfile应该如下所示
FROM node:slim as build
WORKDIR /usr/app
COPY package.json .
COPY public public
COPY src src
RUN npm install
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d
# if you are using react router
# you need to overwrite the default nginx configurations
# remove default nginx configuration file
RUN rm /etc/nginx/conf.d/default.conf
EXPOSE 80https://stackoverflow.com/questions/62853811
复制相似问题