Skip to content

Instantly share code, notes, and snippets.

@tonyseek
Last active May 24, 2022 13:55
Show Gist options
  • Save tonyseek/ae2af27c355263227fbd2b5240a0ac78 to your computer and use it in GitHub Desktop.
Save tonyseek/ae2af27c355263227fbd2b5240a0ac78 to your computer and use it in GitHub Desktop.
~/.local/bin/miniconda3
#!/usr/bin/env bash
set -e
IMAGE="docker.io/continuumio/miniconda3:latest"
HOST_CONDA_DIR="/opt/conda"
HOST_NOTEBOOK_DIR="${PWD}"
HOST_NOTEBOOK_PORT="8888"
podman_cmd=("${@:-/bin/bash}")
podman_opt=()
case "${podman_cmd[0]}" in
setup)
sudo mkdir -p "${HOST_CONDA_DIR}"
tmpcid="$(sudo podman create "${IMAGE}")"
sudo podman cp "${tmpcid}:/opt/conda/." "${HOST_CONDA_DIR}"
sudo podman rm "${tmpcid}"
exit 0
;;
notebook)
if avahi-daemon -c >/dev/null 2>&1; then
jupyter_hostname="$(hostname).local"
else
jupyter_hostname="$(hostname --fqdn)"
fi
jupyter_display_url="http://${jupyter_hostname}:${HOST_NOTEBOOK_PORT}"
jupyter_opt=(
"--ip=0.0.0.0"
"--port=8888"
"--notebook-dir=/opt/notebooks"
"--allow-root"
"--no-browser"
"--NotebookApp.custom_display_url=${jupyter_display_url}")
podman_cmd=(jupyter notebook "${jupyter_opt[@]}")
podman_opt+=(
"-p" "${HOST_NOTEBOOK_PORT}:8888"
"-v" "${HOST_NOTEBOOK_DIR}:/opt/notebooks")
;;
help)
prog="$(basename "$0")"
printf >&2 'e.g. %s {setup,notebook,help}\n' "${prog}"
printf >&2 ' %s [COMMAND]\n' "${prog}"
exit 0
;;
esac
exec sudo podman run -it --rm \
-v "${HOST_CONDA_DIR}:/opt/conda" \
"${podman_opt[@]}" "${IMAGE}" "${podman_cmd[@]}"

Use miniconda3 as containers

Install Host Environment

miniconda3 setup

Install Packages

miniconda3 conda install jupyter numpy scipy matplotlib pandas

Open Shells

miniconda3          # Bash
miniconda3 ipython  # IPython

Open Jupyter Notebook Server

miniconda3 notebook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment