# Building Docker image from jupyter/base-notebook but with a different conda environment

**URL:** <https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890>\
**Category:** JupyterHub\
**Created:** [June 17, 2020, 10:40pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890 "2020-06-17T22:40:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![petebachant](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/petebachant/32/2268_2.png) [@petebachant](https://discourse.jupyter.org/u/petebachant)\
**Post date:** [June 17, 2020, 10:40pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/1 "2020-06-17T22:40:46Z")

</div>

My team and I share an `environment.yml` file so we can all work from the same environment. I’m trying to make this the default for our JupyterHub, but I can’t get the hub to spawn notebooks with this environment, even though it does exist in the conda envs inside the Docker image. I tried modifying the command in the Dockerfile as

```auto
CMD /bin/bash -c ". activate myenv && start-notebook.sh"

```

This works if I run the image directly, but if I try to set it as the image for JupyterHub, notebooks are run in the base environment. Any tips on getting this up and running?

---

<div class="post-metadata">

**Author:** ![1kastner](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/1kastner/32/1537_2.png) [@1kastner](https://discourse.jupyter.org/u/1kastner)\
**Post date:** [June 18, 2020, 11:28am UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/2 "2020-06-18T11:28:01Z")

</div>

Have you had a look at the `post_start_exec` hook at [https://github.com/jupyterhub/dockerspawner/blob/3e3097de582f98e1bcd51a217444c76f95452fc8/dockerspawner/dockerspawner.py#L628](https://github.com/jupyterhub/dockerspawner/blob/3e3097de582f98e1bcd51a217444c76f95452fc8/dockerspawner/dockerspawner.py#L628) ? There is some explanation in the doc string but I am not sure whether the generated documention is hosted somewhere in the web.

---

<div class="post-metadata">

**Author:** ![petebachant](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/petebachant/32/2268_2.png) [@petebachant](https://discourse.jupyter.org/u/petebachant)\
**Post date:** [June 18, 2020, 12:17pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/3 "2020-06-18T12:17:33Z")

</div>

I did try adding `. activate myenv` there with no luck. However, I was able to get my notebooks running in my environment with this in `config.yaml`:

```auto
singleuser:
  defaultUrl: "/lab"
  cmd: ["/bin/bash", "-c", ". activate myenv && jupyterhub-singleuser --SingleUserNotebookApp.default_url=/lab"]

```

Strangely, the `defaultUrl` entry doesn’t seem to have any effect, hence the `--SingleUserNotebookApp.default_url=/lab`.

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [June 18, 2020, 7:07pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/4 "2020-06-18T19:07:26Z")

</div>

`defaultUrl` is [converted into a notebook argument](https://github.com/jupyterhub/jupyterhub/blob/b5defabf495c49a73747dadfbfa9b95abe0be0d6/jupyterhub/spawner.py#L993) that’s [passed to `cmd`](https://github.com/jupyterhub/kubespawner/blob/2530634f0ce683f82ebcf07ddcc2b739ecc5657f/kubespawner/spawner.py#L1397).

Your in-line script doesn’t handle extra arguments. If you replace it with a script that handles `$@` I think it should work as expected.

---

<div class="post-metadata">

**Author:** ![00Kai0](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/00kai0/32/1144_2.png) [@00Kai0](https://discourse.jupyter.org/u/00Kai0)\
**Post date:** [June 26, 2020, 3:09pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/5 "2020-06-26T15:09:49Z")

</div>

@petebachant, Have you seen this: [https://jupyterhub-dockerspawner.readthedocs.io/en/latest/spawner-types.html](https://jupyterhub-dockerspawner.readthedocs.io/en/latest/spawner-types.html).  
It’s about how to use dockerspawner in jupyterhub.

---

<div class="post-metadata">

**Author:** ![00Kai0](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/00kai0/32/1144_2.png) [@00Kai0](https://discourse.jupyter.org/u/00Kai0)\
**Post date:** [June 26, 2020, 3:19pm UTC](https://discourse.jupyter.org/t/building-docker-image-from-jupyter-base-notebook-but-with-a-different-conda-environment/4890/6 "2020-06-26T15:19:17Z")

</div>

And if you have right configuration. You can change different kernels in jupyter notebook.
