Docker Hub上的Docker多目标构建失败

时间:2018-02-15 22:02:07

标签: docker dockerfile

由于未知原因,Docker Hub尝试从刚构建的目标复制到同一个Dockerfile时,构建失败。当我试用本地机器(Fedora 27,Docker CE 17.12)时,构建成功。

此处失败的构建日志:https://hub.docker.com/r/emmanuelgautier/react-app/builds/bsygsbahuzdxfbsqr5r9er4/

1 个答案:

答案 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