Deployment with Docker?

I am starting an internship soon where I will need to become familiar with OpenMC, and I have been reviewing the documentation and would like to try some examples on my system. I am using a Windows system, so I am trying to use OpenMC with docker. I was able to follow the steps in the Devloper’s Guide (7. Deployment with Docker — OpenMC Documentation), and I am now here: “This command will open an interactive shell running from within the Docker container where you have access to use OpenMC.”. – I have this shell running, but I don’t understand how to proceed from here to run my own Python script. An ls command shows me this:

root@86c2a48d914b:/# ls
bin dev home lib32 libx32 mnt proc run srv tmp var
boot etc lib lib64 media opt root sbin sys usr

How do I run some python code that I’ve written using OpenMC now?

Thank you very much for your time.

@LukeLabrie Run your docker image with an interactive bash session.

docker run -it <image> /bin/bash

You can run your python code using the python file_name.py command.

Hope this will help!

Hi Pranto,

When I run that command, instead of seeing “C:\Users\Luke>”, it changes to “root@0e5215463fdf:/#”, which I assume means that the image is running. But now the python file_name.py command does not work. It seems like the image doesn’t have access to these files. Am I missing something?

Thanks for your help.

@LukeLabrie You have to change to the directory where your input file is located.

Ok, Let’s try to run a pincell problem.

$ cd /opt/ && mkdir test_run && cd /opt/test_run
$ cp ../openmc/examples/pincell/build_xml.py .
$ python build_xml.py
$ openmc

Best
pranto

Ok, do you mind explaining what that first command is doing? I looked up the cp command on Docker and it says you need to specify a source and destination. The source I imagine would be my local pin_cell.py file, but how do I specify a destination on the image that I’m going to run in docker?

&& is used for chain commands such that the next command is run if and only if the preceding command exits without error. You can run each command separately

$ cd /opt/
$ mkdir test_run
$ cd /opt/test_run

To refer the destination you can use a dot (.) means copy the file in my current working directory.

@LukeLabrie It sounds like you want to access files on your Windows drive from the docker container. If so, see this question on stackoverflow.

Paul, when I use the volume mount discussed in that post I do see my file in the docker container, but I am still unable to run it. See below:

Running the docker image:
docker run -it --name=my_openmc --rm -v /pin_cell.py debian/openmc:latest

ls command:

root@39c7893610d3:/# ls
bin   dev  home  lib32  libx32  mnt  pin_cell.py  root  sbin  sys  usr
boot  etc  lib   lib64  media   opt  proc         run   srv   tmp  var

As you can see, the file is there. Now I try to run the file:

root@39c7893610d3:/# python pin_cell.py
/usr/bin/python: can't find '__main__' module in 'pin_cell.py'

So I think I’m one step closer here, but still missing something. Any ideas?

Figured it out!

The key is to use an absolute filepath instead of a relative file path, i.e.

docker run -it --name=my_openmc1 --rm -v $pwd/pin_cell.py:/containerdir debian/openmc:latest

Instead of:

docker run -it --name=my_openmc1 --rm -v /pin_cell.py:/containerdir debian/openmc:latest

Thank you pranto and thank you Paul for your time and guidance.

Luke

Another option for running files within the Docker container is to install VScode on windows along with the Remote Contain addition. This provides a terminal and a IDE that inherits from the container.