How to reuse your environments

Tired of always installing the same packages, or downloading the same data every time you start with a new notebook? In Nextjournal, you can avoid this by exporting a snapshot of your environment's file system as a Docker image. This way, you'll be able to reuse your environment (and all the packages/files you have installed already) by subsequently importing it into other notebooks, in your local machine, or share it with anyone. Let's see how to do this.

1. Export your environment

Step 1: open your runtime settings

To save an environment, open the associated runtime's settings (the ⚙️ icon next to the runtime's name).

Reminder: you can have multiple runtimes, and as a consequence multiple independent environments within your notebook, that you can export.

Step 2: add a name, and export

Next, add a name for your environment (optional, but strongly recommended as it makes it easier to find later on), and enable the Export the environment toggle, at the bottom of the dialog.

Exporting an environment has the additional benefit of notifying you about all changes to it since you last saved it. This is especially helpful when you, e.g., upgrade drivers or packages. Resetting the runtime will revert it to the last saved environment’s state.

Further, exporting will also give you a URL that you can use with the docker pull command, to be found in the runtime settings below the toggle:

Step 3: review, and save

Now, close the dialog, go under the runtime's name in the sidebar to review the changes, and save your environment:

Done! A snapshot of your environment's file system has been created and uploaded to Nextjournal's Docker registry. Now you can import it in other notebooks, or use the docker pull command to download it. Keep reading to see how to import it.

2. Import your environment

Step 1: add a code cell

The first step is (if you haven't done so already) to add a code cell in the language that you want to use your environment with. This will create the corresponding runtime.

Step 2: open the runtime settings

Open the runtime settings (using the ⚙️ button next to the runtime's name) for which you wish to import the environment.

Then, go to the Environment section, and look for the Import environment ... option:

You will be prompted to enter the profile, and subsequently the notebook (and the version of it) from which you exported the environment.

Step 3: save, and restart

Lastly, save your changes and restart your runtime. That's it! You'll be able to use anything included in the environment you've just imported right away.