小编Myk*_*lov的帖子

Dockerfile:复制文件夹(如果存在)(有条件复制)

我有用于 NodeJS 应用程序的 Dockerfile,需要复制容器内的迁移、种子文件夹。但问题是我们所有的应用程序都使用相同的 Dockerfile,但并非所有应用程序都与 DB 一起使用并具有迁移、种子。

Dockerfile:

...
# * package json, to be able run `npm run ...`
COPY ./package.json /app/
# * migrations, seeds if they exist
COPY ./migrations/ /app/migrations/
COPY ./seeds/ /app/seeds/
...
Run Code Online (Sandbox Code Playgroud)

一切正常,但如果我们没有迁移文件夹,我们将得到:

 => CACHED [app 4/9] COPY --from=builder /app/node_modules /app/node_modules                                                                                                                                                                                              0.0s
 => CACHED [app 5/9] COPY --from=builder /app/dist /app/dist                                                                                                                                                                                                              0.0s
 => CACHED [app 6/9] COPY ./package.json /app/                                                                                                                                                                                                                            0.0s
 => ERROR [app 7/9] COPY ./migrations/ /app/migrations/                                                                                                                                                                                                                   0.0s
------
 > …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

docker ×1

dockerfile ×1