在我的Dockerfile我有:

ADD ../../myapp.war /opt/tomcat7/webapps/

该文件以ls ../../myapp的形式存在。war返回我正确的文件,但当我执行sudo docker构建-t myapp。我有:

Step 1 : ADD ../../myapp.war /opt/tomcat7/webapps/
2014/07/02 19:18:09 ../../myapp.war: no such file or directory

有人知道为什么和如何正确地做吗?


当前回答

如果你正在使用skaffold,使用'context:'为每个图像指定上下文位置dockerfile - context: ../../../

            apiVersion: skaffold/v2beta4
            kind: Config
            metadata:
                name: frontend
            build:
                artifacts:
                    - image: nginx-angular-ui
                      context: ../../../
                      sync:
                          # A local build will update dist and sync it to the container
                          manual:
                              - src: './dist/apps'
                                dest: '/usr/share/nginx/html'
                      docker:
                          dockerfile: ./tools/pipelines/dockerfile/nginx.dev.dockerfile
                    - image: webapi/image
                      context: ../../../../api/
                      docker:
                          dockerfile: ./dockerfile
            deploy:
                kubectl:
                    manifests:
                        - ./.k8s/*.yml

运行-f ./ Skaffold .yaml

其他回答

由于-f引起了另一个问题,我开发了另一个解决方案。

在父文件夹中创建一个基本映像 添加所需文件。 使用此图像作为子代文件夹中项目的基本图像。

-f标志并没有解决我的问题,因为我的onbuild映像在一个文件夹中寻找一个文件,并且必须像这样调用:

-f foo/bar/Dockerfile foo/bar

而不是

-f foo/bar/Dockerfile .

还要注意,这只是在某些情况下使用-f标志的解决方案

如果你正在使用skaffold,使用'context:'为每个图像指定上下文位置dockerfile - context: ../../../

            apiVersion: skaffold/v2beta4
            kind: Config
            metadata:
                name: frontend
            build:
                artifacts:
                    - image: nginx-angular-ui
                      context: ../../../
                      sync:
                          # A local build will update dist and sync it to the container
                          manual:
                              - src: './dist/apps'
                                dest: '/usr/share/nginx/html'
                      docker:
                          dockerfile: ./tools/pipelines/dockerfile/nginx.dev.dockerfile
                    - image: webapi/image
                      context: ../../../../api/
                      docker:
                          dockerfile: ./dockerfile
            deploy:
                kubectl:
                    manifests:
                        - ./.k8s/*.yml

运行-f ./ Skaffold .yaml

添加一些代码片段来支持接受的答案。

目录结构:

setup/
 |__docker/DockerFile
 |__target/scripts/<myscripts.sh>
src/
 |__<my source files>

Docker文件入口:

RUN mkdir -p /home/vagrant/dockerws/chatServerInstaller/scripts/
RUN mkdir -p /home/vagrant/dockerws/chatServerInstaller/src/
WORKDIR /home/vagrant/dockerws/chatServerInstaller

#Copy all the required files from host's file system to the container file system.
COPY setup/target/scripts/install_x.sh scripts/
COPY setup/target/scripts/install_y.sh scripts/
COPY src/ src/

用于构建docker映像的命令

docker build -t test:latest -f setup/docker/Dockerfile .

改为CD到父目录 从父目录构建映像,指定Dockerfile的路径

docker build -t <some tag> -f <dir/dir/Dockerfile> .

在这种情况下,docker的上下文将切换到父目录,供ADD和COPY访问

让设置上下文:../..docker-compose.yml父文件夹中的/ 例:

app:
    build:
      context: ../../
      dockerfile: ./source/docker/dockerfile/Dockerfile