Workflow of Docker + jupyter notebook with dolfinx

I am trying to setup a jupyter notebook workflow with fenicsx, using docker (so that I can run some code to solve PDEs with my friend). However, I am confused and having trouble to set these things up (we’re using linux distributions and have jupyter and docker working fine).

I have found some command on GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment to run a standalone jupyter lab environment with fenicsx: docker run --init -ti -p 8888:8888 dolfinx/lab:latest.
That works fine. However I don’t know how to start back the session once I have closed it. Re-running the command will just start a fresh new session, and I cannot access to my work.

Then there is an in-depth guide on how to use Fenics with docker at FEniCS in Docker — FEniCS Containers 1.0 documentation. There is a section with Jupyter notebooks. I am guessing I can make some simple modifications in the commands for them to work. But I am not sure this is the recommended way to setup a workflow with fenicsx, jupyter and docker.

How do you people do it? Is there a guide I am missing?

The commands you need to add for sharing directories from your system to the docker system is -v, see: 2. Introduction — FEniCS Containers 1.0 documentation
To resume a session, it is suggested to create a container with a name, i.e —name=fenicsx_lab
As explained in: 2. Introduction — FEniCS Containers 1.0 documentation

I see, thanks for the reply. I have no luck so far. For example docker run --init -p 8888:8888 -v "$(pwd)":/root/shared dolfinx/lab:latest lets me access a jupyter notebook with dolfinx. However, saving the notebook file doesn’t make it appear on my host system, despite the -v argument (and I am running this command from a terminal opened in a dedicated directory I wish to share with the docker image).

I also tried

docker run --init -p 8888:8888 -v "$(pwd)":/root/shared dolfinx/lab:latest --name dolfinx_test0

But then I get the message: [W 2022-06-12 12:56:44.606 ServerApp] Unrecognized alias: 'name', it will have no effect.

And I can see that indeed, no docker image was created with the name I picked, by using docker ps -a.

Did you navigate to /root/shared and created the notebook there in the Lab interface? Might be worthwhile adding -w /root/shared

You are missing an equals here:
docker run --init -p 8888:8888 -v "$(pwd)":/root/shared --name=dolfinx_test0 dolfinx/lab:latest

2 Likes

Oops, I placed the file right outside the shared directory, so directly in /root I think. It works now! Thanks a lot!

Thanks also for the correction with the = sign.

I guess I am all set up. I can now help my friend. Thanks a million dokken!!!

dokken, I realize that this command creates a new docker container each time I run it. As a result, I am left with tens of containers, is this the usual way people use docker/jupyter/fenicsx? Or am I doing something wrong?

If you have Added —name=somename it creates a container with a specific name, that you can restart by calling docker container start -i somename

1 Like

Thank you very much again, dokken. (Sorry for these basic questions!)

Hi all,

I have been now trying to open a Jupiter notebook to work with dolfinx via docker for a while. I followed the instructions here and thoroughly read the documentation at FEniCS Containers and tried different combinations.

The command I was using is:

docker run --init -ti -p 8888:8888 --name=dolfinx_test1_notebook -w /root/shared -v /Users/mestroni/Documents/Docker_fenics:/root/shared dolfinx/lab:stable

I have tried this command both with the dolfinx/lab image (either with tag nightly or stable - I could not find it anywhere with the tag latests used here) or the image dokken92/dolfinx_custom:v0.5.0.
I also tried it avoiding naming the container/ without specifying the -w, -ti, --name and -v options.

The container is always running but I am unable to access any of the links provided in any possible combination I tried. The link opens a web age even saying
'404 : Not Found
You are requesting a page that does not exist!’

or

Safari can’t find the server

I further tried to run Jupiter from within the running container with

jupyter-notebook --allow-root

or

jupyter lab --allow-root

always obtaining the same error messages.
Also, it seems that I am not allowed to navigate to /root/shared from within the container.

What am I missing?

Thank you!

@martamestroni Are you using WSL? I can’t reproduce this error on Ubuntu but I see the same error when launching the dolfinx/lab image inside WSL on Windows. If so, you can try the suggestion in this bug report on the WSL GitHub: Can't connect to docker container running inside WSL2 · Issue #4983 · microsoft/WSL · GitHub

I.e. launch the Docker container using

podman run --init -it --name dolfinx-lab -v ~:/mnt/home -p 8888:8888 --rm dolfinx/lab

copy the link for the Jupyter Lab server, e.g.

http://127.0.0.1:8888/lab?token=81c60c3d8f39b18c6ad0ef04210994c62fa712c6d0db1a99

paste in your web browser and replace 127.0.0.1 with [::1]

http://[::1]:8888/lab?token=81c60c3d8f39b18c6ad0ef04210994c62fa712c6d0db1a99

This solved the issue on my WSL setup.