Docker没有将子目录复制到Container中 [英] Docker is not copying subdirectory into Container
问题描述
我具有以下目录结构
|-Dockerfile
|-README.md
|-angula.json
|-package.json
|-...
|-src
|-index.html
|-main.ts
|-...
|app
|-app.component.html
|...
现在,我希望所有内容在启动时都被复制到一个容器中.为此,我将以下内容放入了Dockerfile中:
Now I want that everything is copied into a container when it is starting up. For that I put the following content into the Dockerfile:
From node:12.15.0-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app/
RUN ["npm","install"]
COPY . /app
EXPOSE 4200/tcp
CMD ["npm", "start", "--", "--host", "0.0.0.0", "--poll", "500"]
现在我构建并运行Dockerfile时,遇到以下问题,即未复制目录 src
及其所有子目录.
When I now build and run the Dockerfile, I have the following issue, that the directory src
and all its subdirectories are not copied.
当我运行 docker exec -it [container-name] sh
,然后键入 sh
时,与Dockerfile位于同一目录中的所有文件都在那里.但是,如果我进入 src
文件夹,则该文件夹为空.
When I run docker exec -it [container-name] sh
and then type sh
all files which are in the same directory as Dockerfile are there. However if I then go into the src
folder it is empty.
我希望使用 COPY./app
我正在将整个文件夹及其所有子目录都处理到容器中.为什么不是这样?我错过了什么?
I would expect that with the COPY . /app
I am coping the complete folder and all its sub-directories to the container. Why is this not the case? What am I missing out?
推荐答案
这是一个非常愚蠢的错误...当我安装 src
目录时,我使用的是 $ {pwd}
而不是 $(pwd)
,尽管我之前已复制,但它导致了空文件夹.
It was a very stupid mistake... When I mounted the src
directory I used ${pwd}
instead of $(pwd)
, which lead to the empty folder, eventhough I copied previously.
这篇关于Docker没有将子目录复制到Container中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!