Search code examples
dockerpysparkjupyter-notebooklocalhostcontainers

Mis-understand of copy file in docker images


Hello could someone pleas help me on copying docker(I'm starter) host file into my jupyter/pyspark-notebook images. I've pulled this notebook from docker as public available.

I've created a Dockerfile which contains this.

FROM jupyter/pyspark-notebook:latest
ADD /home/abdoulaye/Documents/M2BIGDATA/Jaziri /bin/bash

I've changed /bin/bash to . but nothing is visible. when I execute docker built it's like it copy files as shown in output below. img when I go to my my notebook I did note found folders. I check my snapshot if I can found these copied folder but I'm very confused.

In clear, I've an running notebook in my docker I use it in y navigator but I can not load data. I like to copy data in place where I can access it in notebook. img2


Solution

  • You can not copy using absoult path, the path should be relative to Dockerfile, so /home/abdoulaye/Documents/M2BIGDATA/Jaziri this path inside Dockerfile is not correct. Copy file to Dockerfile context and then copy like

    ADD M2BIGDATA/Jaziri /work
    

    Now First thing, you should not copy files from host to executable files directory.

    For instance,

    FROM alpine
    copy hello.txt /bin/sh
    
    

    If you copy like this, it will create a problem to run command inside container as sh or bash will be replaced or corrupt.

    2nd, while you are building the docker image with invalid context, it should be the same where your Dockerfile is, so better to run the directory where you place the Dockerfile.

    docker build -t my-jupyter .
    

    3rd, you should not run cp command inside container to copy files from host to container.

    docker cp /home/abdoulaye/Documents/M2BIGDATA/Jaziri container_id:/work
    

    it will copy your files to /work path of the container.