Warning, /JETSCAPE/docker/README.md is written in an unsupported language. File is not indexed.
0001 ## Using JETSCAPE via Docker
0002
0003 Docker is a software tool that allows one to deploy an application in a portable environment.
0004 A docker "image" can be created for the application, allowing any user to run a docker "container" from this image.
0005 We have prepared a docker image for the JETSCAPE environment, which allows you to use JETSCAPE on macOS or linux without
0006 installing a long list of pre-reqs or worrying about interference with software you already have installed. Step-by-step instructions are provided below.
0007
0008 For those unfamiliar with Docker: To illustrate what this will look like, consider the following standard workflow.
0009 In a terminal on your machine (call it Terminal 1), you will clone JETSCAPE — this terminal is on your "host" machine —
0010 just a standard, typical terminal. In another terminal (call it Terminal 2), you will invoke a command that runs a pre-defined docker container.
0011 Terminal 2 then lives entirely inside this docker container, completely separated from your host machine. It can *only* access the files that
0012 are inside that pre-defined docker container — and not any of the files on your host machine — unless we explicitly share a
0013 folder between them. The standard workflow that we envision is the following: You will share the folder containing JETSCAPE between the
0014 host machine and the docker container. Then, anytime you want to **build** or **run** JETSCAPE, you *must* do it inside the docker container.
0015 But anytime you want to edit text files (e.g. to construct your own configuration file), or analyze your output files, you can do this from your
0016 host machine (which we recommend). Simple as that: Depending which action you want to do, perform it either on the host machine,
0017 or in the docker container, as appropriate — otherwise it will not work.
0018
0019 ### Step 1: Install Docker
0020
0021 #### macOS
0022
0023 1. Install Docker Desktop for Mac: https://docs.docker.com/docker-for-mac/install/
0024 2. Open Docker, go to Preferences --> Advanced and
0025 - (i) Set CPUs to max that your computer has (`sysctl -n hw.ncpu`),
0026 - (ii) Set memory to what you are willing to give Docker.
0027
0028 #### linux
0029
0030 1. Install Docker: https://docs.docker.com/install/
0031 2. Allow your user to run docker (requires admin privileges):
0032 ```
0033 sudo groupadd docker
0034 sudo usermod -aG docker $USER
0035 ```
0036 Log out and log back in.
0037
0038 For **Windows**, please follow the analogous instructions: https://docs.docker.com/install/
0039
0040 Please note that if you have an older OS, you may need to download an older version of docker.
0041
0042 ### Step 2: Run JETSCAPE
0043
0044 The docker container will contain only the pre-requisite environment to build JETSCAPE, but will not actually contain JETSCAPE itself. Rather, we will create a directory on our own machine with the JETSCAPE code, and share this directory with the docker container. This will allow us to build and run JETSCAPE inside the docker container, but to easily edit macros and access the output files on our own machine.
0045
0046 1. Make a directory on your machine (which will be shared with the docker container), and clone JETSCAPE into it.
0047 ```
0048 mkdir ~/jetscape-docker
0049 cd ~/jetscape-docker
0050 git clone https://github.com/JETSCAPE/JETSCAPE.git
0051 ```
0052
0053 In what follows we assume such a directory at `~/jetscape-docker`. You may decide to name your directory something else,
0054 but if so **please be careful to substitute your directory name appropriately in the instructions below**.
0055
0056 2. Create and start a docker container that contains all of the JETSCAPE pre-reqs:
0057
0058 **macOS:**
0059 ```
0060 docker run -it -v ~/jetscape-docker:/home/jetscape-user --name myJetscape jetscape/base:stable
0061 ```
0062
0063 **linux:**
0064 ```
0065 docker run -it -v ~/jetscape-docker:/home/jetscape-user --name myJetscape --user $(id -u):$(id -g) jetscape/base:stable
0066 ```
0067
0068 For details on the compatibility of docker image versions with JETSCAPE versions, please see the [jetscape dockerhub](https://hub.docker.com/r/jetscape/base) page.
0069
0070 This is what the `docker run` command does:
0071 - `docker run` creates and starts a new docker container from a pre-defined image jetscape/base:stable, which will be downloaded if necessary.
0072 - `-it` runs the container with an interactive shell.
0073 - `-v` mounts a shared folder between your machine (at ~/jetscape-docker) and the container (at /home/jetscape-user), through which you can transfer files to and from the container. You can edit the location of the folder on your machine as you like.
0074 - `--name` (optional) sets a name for your container, for convenience. Edit it as you like.
0075 - `--user $(id -u):$(id -g)` (only needed on linux) runs the docker container with the same user permissions as the current user on your machine (since docker uses the same kernel as your host machine, the UIDs are shared). Note that the prompt will display "I have no name!", which is normal.
0076
0077 Note that on linux, you may want to add the option `--memory <limit>` to limit the amount of memory that docker is allowed to
0078 consume (by default, the available memory and CPUs are not limited on linux, since it is not run in a VM as in macOS).
0079
0080 Some useful commands:
0081 - To see the containers you have running, and get their ID: `docker container ls` (`-a` to see also stopped containers)
0082 - To stop the container: `docker stop <container>` or `exit`
0083 - To re-start the container: `docker start -ai <container>`
0084 - To put a running container into detatched mode: `Ctrl-p Ctrl-q`, and to re-attach: `docker attach <container>`
0085 - To delete a container: `docker container rm <container>`
0086
0087 For example to exit and re-enter the docker container:
0088 ```
0089 [From inside the container]
0090 exit
0091
0092 [Now we are outside the container]
0093 docker container ls -a
0094 ...
0095 docker start -ai myJetscape
0096
0097 [Now we are inside the container again]
0098 ```
0099
0100 You may find it useful to keep two terminals open — one inside the docker container, and one outside the container —
0101 so that you can easily execute commands either inside or outside the container, as appropriate.
0102
0103 3. Build JETSCAPE:
0104
0105 From **inside** the docker container, we can now build JETSCAPE:
0106
0107 ```
0108 cd JETSCAPE
0109 mkdir build
0110 cd build
0111 cmake ..
0112 make -j4 # Builds using 4 cores; adapt as appropriate
0113 ```
0114
0115 *That's it!* You are now inside the docker container, with JETSCAPE and all of its prequisites installed.
0116 You can run JETSCAPE executables or re-compile code. Moreover, since we set up the jetscape-docker folder to be shared between your
0117 host and the docker container, you can do text-editing etc. on your host machine, and then immediately build JETSCAPE in the docker container.
0118 Output files are also immediately accessible on your host machine if desired.