由于未知原因,Docker Hub尝试从刚构建的目标复制到同一个Dockerfile时,构建失败。当我试用本地机器(Fedora 27,Docker CE 17.12)时,构建成功。
此处失败的构建日志:https://hub.docker.com/r/emmanuelgautier/react-app/builds/bsygsbahuzdxfbsqr5r9er4/
答案 0 :(得分:1)
第二张图片中不存在文件夹/usr/src/app/build
,因为根据documentation:
应该使用
CMD
在构建时不执行任何操作,但指定了 预期的图像命令。
RUN
代替执行CMD
命令的yarn build
。
正确的Dockerfile
是:
## Development environment target
FROM node as dev-env
WORKDIR /usr/src/app
COPY [ "package*.json", "yarn.lock", "./" ]
RUN yarn install
COPY . .
EXPOSE 3000
ENTRYPOINT [ "./docker-entrypoint.sh" ]
## Build environment target
FROM node as build-env
WORKDIR /usr/src/app
COPY [ "package*.json", "yarn.lock", "./" ]
RUN yarn install --production
COPY . .
RUN yarn build
## Production environement target
FROM nginx as production-env
LABEL MAINTAINER Emmanuel Gautier <docker@emmanuelgautier.fr>
COPY --from=1 /usr/src/app/build /usr/share/nginx/html
EXPOSE 443 80