I’m creating a course that will require students to run some software called PyStan. It turns out that this is partially supported on Windows.
Someone gave me an idea to use Docker so that students wouldn’t have any issue getting the software they need to do assignments. The end goal is that students can do very little to get Jupyter Lab up and running on their own machines, with as little effort as possible.
I tried writing the following to be run with sudo docker compose up
version: '3'
services:
ubuntu_anaconda:
image: continuumio/anaconda3:latest
container_name: ubuntu_anaconda
environment:
- LANG=C.UTF-8
- JUPYTER_TOKEN=my_secret_token # Set your desired token here
ports:
- "8888:8888" # Expose Jupyter Lab port
volumes:
- ./data:/data # Add this line if you want to mount a local directory to the container
command: /bin/bash -c "/opt/conda/bin/conda install -y -c conda-forge pystan && /opt/conda/bin/jupyter lab --ip=0.0.0.0 --port=8888 --allow-root --NotebookApp.token=${JUPYTER_TOKEN}"
However, the first line of the output warns me that
WARN[0000] The "JUPYTER_TOKEN" variable is not set. Defaulting to a blank string.
I am using Docker version 25.0.3.
2
Answers
The JUPYTER_TOKEN variable not being set in your Docker Compose
file, you can either explicitly define its value or remove it if not
needed. If setting a token, replace
my_secret_token
with yourdesired token. After updating the file, running
sudo docker-compose up
again should eliminate the warning.2.Using .env file:
Create a
.env
file in the same directory as yourdocker-compose.yml
.Define variables in the
.env
file (e.g JUPYTER_TOKEN=my_secret_token # Set your desired token ).In
docker-compose.yml
, reference these variables using ${VARIABLE_NAME}syntax. Docker compose automatically reads variables from the .env file in the current directory.
As mentioned in the other answer you can use a
.env
file. You can also specify the token on the command line: