简体   繁体   English

docker 构建文件复制文件带方括号

[英]docker build file copying files with square brackets

I've been using a docker build file to build my nextjs node application fine for a long while, but today I added nextjs dynamic pages.很长一段时间以来,我一直在使用 docker 构建文件来构建我的 nextjs 节点应用程序,但今天我添加了 nextjs 动态页面。 These pages are named with square brackets eg [page].js这些页面以方括号命名,例如 [page].js

If i remove this file my docker file builds fine, so it's definitely to do with the square brackets, but I don't know how to solve this problem.如果我删除这个文件,我的 docker 文件构建得很好,所以它肯定与方括号有关,但我不知道如何解决这个问题。

Here's my Docker file:这是我的 Docker 文件:

FROM node:10.13-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 3000
RUN npm run build
CMD ["npm", "start"]

and here's the error这是错误

Error: Could not find a valid build in the '/home/node/app/.next' directory!

And as I say, it's started since i've added the square brackets in the filename.正如我所说,它是从我在文件名中添加方括号开始的。 Unfortunately these files must be named with square brackets to function correctly不幸的是,这些文件必须用方括号正确命名为 function

According to the COPY documentation ,根据COPY 文档

When copying files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern.在复制包含特殊字符(例如 [ 和 ] )的文件或目录时,您需要按照 Golang 规则对这些路径进行转义,以防止它们被视为匹配模式。 For example, to add a file named arr[0].txt, use the following;例如,要添加名为 arr[0].txt 的文件,请使用以下命令;

ADD arr[[]0].txt /mydir/

The only solution that I've been able to find is to copy files with special symbols one by one escaping special characters.我能找到的唯一解决方案是一个一个地复制带有特殊符号的文件 escaping 特殊字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM