Passing a file from my PC to a docker container (dolfinx)

Hi all,

I’m trying to run this dolfinx demo file, using docker. My OS is Ubuntu 20.04 LTS. In order to do so, I tried to copy my local version of the demo file (that is in the folder dolfinx-demos) into the docker container, executing the following commands:

sudo docker run -ti dolfinx/dolfinx
root@container-id:~# mkdir helmholtz
root@container-id:~# exit
cd dolfinx-demos
sudo docker start container-id
sudo docker cp demo_helmholtz_2d.py container-id:/helmholtz

Unfortunately, nothing gets copied in the container folder (ls command gives an empty list):

sudo docker exec -ti container-id bash
root@container-id:~# cd helmholtz
root@container-id:~/helmholtz# ls
root@container-id:~/helmholtz#

What am I doing wrong? How can I pass files from host to container? With the help of this guide, I had no problem in doing that with the stable version of fenics, but it seems that in dolfinx it is different.

Thank you very much for your patience.

The command I would run is the following:

 docker run -ti -v $(pwd):/root/shared -w /root/shared  dolfinx/dolfinx

Here -v shares a volume, $(pwd) the current folder you are in, to the location root shared in the docker container. -w indicates what the working directory should be, which is where the docker container will start. I have set this to the directory you want to share.

2 Likes

Thank you very much @dokken ! Your help is precious as always! Just one other question: is /root/shared a “special” Docker folder? Why can I share files only with that folder?

1 Like

You can share to any folder inside the docker container. The reason for choosing this path is:

  1. The user in the docker container is the root user, therefore one would like to share it to some path that the user owns.
  2. The reason for calling the directory shared and not something else, is to remind you that the files in this folder are those from your computer. If you delete a file in this folder, it is also deleted on your system.
1 Like

Perfect! I was missing point 1. Thank you so much again.