在我的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

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


当前回答

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

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

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

-f foo/bar/Dockerfile foo/bar

而不是

-f foo/bar/Dockerfile .

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

其他回答

对于那些使用composer的人来说,解决方案是使用指向父文件夹的卷:

#docker-composer.yml

foo:
  build: foo
  volumes:
    - ./:/src/:ro

但是我很确定可以在Dockerfile中处理卷。

使用docker-compose,你可以设置上下文文件夹:

# docker-compose.yml

version: '3.3'    
services:
  yourservice:
    build:
      context: ./
      dockerfile: ./docker/yourservice/Dockerfile

从上目录构建img 命名为img 启用适当的卷共享 查看上面链接中的Makefile,了解如何启动容器… Docker构建。-t proj-devops-img——no-cache——build-arg UID=$(shell id -u)——build-arg GID=$(shell id -g) -f src/docker/devops/Dockerfile . t

如果你正在使用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 .