BUILD_DIR
之后, ARG FROM
错过了。
我做错了什么?
Dockerfile:
# build
# одноразовый контейнер
FROM node:latest as build
ARG BUILD_DIR=/build
# создание директории приложения
WORKDIR $BUILD_DIR
# установка зависимостей
# символ астериск ("*") используется для того чтобы по возможности
# скопировать оба файла: package.json и package-lock.json
COPY package*.json \
tsconfig.json \
./
COPY src src
RUN echo ${BUILD_DIR}
RUN npm i
RUN npm run build
# ---------------------------------------
# build end
#
# app
# ---------------------------------------
RUN echo "1\n"; test -n "$BUILD_DIR" || (echo "BUILD_DIR not set" && false)
FROM node:14-alpine as production
RUN echo "2\n"; test -n "$BUILD_DIR" || (echo "BUILD_DIR not set" && false)
ARG PM2_CONFIG=out/config/ecosystem.config.js
#RUN apt-get update && apt-get install -y \
# build-essential
RUN npm i -g pm2
# создание директории приложения
WORKDIR /usr/local/app
RUN echo ${BUILD_DIR}
COPY --from=build /build/out out
COPY --from=build /build/node_modules node_modules
#EXPOSE # бот использует поллинг
CMD pm2 start ${PM2_CONFIG} && pm2 logs
部分输出是
Step 9/18 : RUN echo "1\n"; test -n "$BUILD_DIR" || (echo "BUILD_DIR not set" && false)
---> Running in c7b0a92fc970
1
Removing intermediate container c7b0a92fc970
---> 977a5ec0be6f
Step 10/18 : FROM node:14-alpine as production
---> 87c43f8d8077
Step 11/18 : RUN echo "2\n"; test -n "$BUILD_DIR" || (echo "BUILD_DIR not set" && false)
---> Running in e2b3de94bb3a
2\n
BUILD_DIR not set
The command '/bin/sh -c echo "2\n"; test -n "$BUILD_DIR" || (echo "BUILD_DIR not set" && false)' returned a non-zero code: 1
docker版本:19.03.8
答案 0 :(得分:1)
ARG BUILD_DIR=/build
# build
# одноразовый контейнер
FROM node:14 as build
ARG BUILD_DIR
有global and local scope 全局可以翻译成每个容器的本地