Can't create a docker image for COPY failed: stat /var/lib/docker/tmp/docker-builder error

前端 未结 18 1910
余生分开走
余生分开走 2020-12-03 00:07

I want to create a docker image. This is my work directory: Dockerfile.in test.json test.py

And this is my Dockerfile:

COPY ./test.json /home/tes         


        
相关标签:
18条回答
  • 2020-12-03 00:53

    Another potential cause is that docker will not follow symbolic links by default (i.e don't use ln -s).

    0 讨论(0)
  • 2020-12-03 00:57

    Check if there's a .dockerignore file, if so, add:

    !mydir/test.json
    !mydir/test.py
    
    0 讨论(0)
  • 2020-12-03 00:59
    1. Q1: Check your .dockerignore file in build path, the files or dir you want to copy may be in the ignore file list!
    2. Q2: The COPY directive is based on the context in which you are building the image, so be aware of any problems with the directory where you are currently building the image! See: https://docs.docker.com/engine/reference/builder/#copy
    0 讨论(0)
  • 2020-12-03 00:59

    The following structure in docker-compose.yaml will allow you to have the Dockerfile in a subfolder from the root:

    version: '3'
    services:
      db:
        image: postgres:11
        environment:
          - PGDATA=/var/lib/postgresql/data/pgdata
        volumes:
          - postgres-data:/var/lib/postgresql/data
        ports:
          - 127.0.0.1:5432:5432
      **web:
        build: 
          context: ".."
          dockerfile: dockerfiles/Dockerfile**
        command: ...
    ...
    

    Then, in your Dockerfile, which is in the same directory as docker-compose.yaml, you can do the following:

    ENV APP_HOME /home
    
    RUN mkdir -p ${APP_HOME}
    
    # Copy the file to the directory in the container
    COPY test.json ${APP_HOME}/test.json
    COPY test.py ${APP_HOME}/test.py
    
    # Browse to that directory created above
    WORKDIR ${APP_HOME}
    

    You can then run docker-compose from the parent directory like:

    docker-compose -f .\dockerfiles\docker-compose.yaml build --no-cache
    
    0 讨论(0)
  • 2020-12-03 01:00

    In my case, it was the comment line that was messing up the COPY command

    I removed the comment after the COPY command and placed it to a dedicated line above the command. Surprisingly it resolved the issue.

    Faulty Dockerfile command

    COPY qt-downloader .     # https://github.com/engnr/qt-downloader -> contains the script to auto download qt for different architectures and versions
    

    Working Dockerfile command

    # https://github.com/engnr/qt-downloader -> contains the script to auto download qt for different architectures and versions
    COPY qt-downloader .     
    

    Hope it helps someone.

    0 讨论(0)
  • Removing ./ from source path should resolve your issue:

     COPY test.json /home/test.json
     COPY test.py /home/test.py
    
    0 讨论(0)
提交回复
热议问题