Skip to content

Commit

Permalink
Update dockerfile to PyMC v4 (pymc-devs#5881)
Browse files Browse the repository at this point in the history
* rename and update build docker container
* add a script for running docker container from bash
* update running docker container from juppyter notebook
* simplify into one bash script
* remove root user from Dockerfile
* remove obsolete scripts
* update documents on running PyMC in Docker
  • Loading branch information
danhphan authored Jun 18, 2022
1 parent f9b749b commit 0ba47b5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 165 deletions.
31 changes: 1 addition & 30 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,5 @@ Quick links
* [Pull request (PR) checklist](https://docs.pymc.io/en/latest/contributing/pr_checklist.html)
* [Python style guide with pre-commit](https://docs.pymc.io/en/latest/contributing/python_style.html)
* [Running the test suite](https://docs.pymc.io/en/latest/contributing/running_the_test_suite.html)
* [Running PyMC in Docker](https://docs.pymc.io/en/latest/contributing/docker_container.html)
* [Submitting a bug report or feature request](https://github.com/pymc-devs/pymc/issues)

<!-- Commented out because our Docker image is outdated/broken.
## Developing in Docker
We have provided a Dockerfile which helps for isolating build problems, and local development.
Install [Docker](https://www.docker.com/) for your operating system, clone this repo, then
run `./scripts/start_container.sh`. This should start a local docker container called `pymc`,
as well as a [`jupyter`](http://jupyter.org/) notebook server running on port 8888. The
notebook should be opened in your browser automatically (you can disable this by passing
`--no-browser`). The repo will be running the code from your local copy of `pymc`,
so it is good for development.
You may also use it to run the test suite, with
```bash
$ docker exec -it pymc bash # logon to the container
$ cd ~/pymc/tests
$ . ./../../scripts/test.sh # takes a while!
```
This should be quite close to how the tests run on TravisCI.
If the container was started without opening the browser, you
need the notebook instances token to work with the notebook. This token can be
accessed with
```
docker exec -it pymc jupyter notebook list
```
-->
18 changes: 18 additions & 0 deletions docs/source/contributing/docker_container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(docker_container)=
# Running PyMC in Docker

We have provided a Dockerfile which helps for isolating build problems, and local development.
Install [Docker](https://www.docker.com/) for your operating system, clone this repo, then
run the following commands to build a `pymc` docker image.

```bash
cd pymc
bash scripts/docker_container.sh build
```

After successfully building the docker image, you can start a local docker container called `pymc` either from `bash` or from [`jupyter`](http://jupyter.org/) notebook server running on port 8888.

```bash
bash scripts/docker_container.sh bash # running the container with bash
bash scripts/docker_container.sh jupyter # running the container with jupyter notebook
```
38 changes: 25 additions & 13 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
FROM jupyter/minimal-notebook
FROM jupyter/base-notebook:python-3.9.12

ARG SRC_DIR=.
LABEL name="pymc"
LABEL description="Environment for PyMC version 4"

MAINTAINER Austin Rochford <[email protected]>
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

ADD $SRC_DIR /home/jovyan/
RUN /bin/bash /home/jovyan/scripts/create_testenv.sh --global --no-setup
# Switch to jovyan to avoid container runs as root
USER $NB_UID

# matplotlib nonsense
ENV XDG_CACHE_HOME /home/$NB_USER/.cache/
ENV MPLBACKEND=Agg
# for prettier default plot styling
RUN pip install seaborn
# Import matplotlib the first time to build the font cache.
RUN python -c "import matplotlib.pyplot"
COPY /conda-envs/environment-dev-py39.yml .
RUN mamba env create -f environment-dev-py39.yml && \
/bin/bash -c ". activate pymc-dev-py39 && \
mamba install -c conda-forge -y pymc" && \
conda clean --all -f -y

ENV PYTHONPATH $PYTHONPATH:"$HOME"
# Fix PkgResourcesDeprecationWarning
RUN pip install --upgrade --user setuptools==58.3.0

#Setup working folder
WORKDIR /home/jovyan/work

# For running from bash
SHELL ["/bin/bash","-c"]
RUN echo "conda activate pymc-dev-py39" >> ~/.bashrc && \
source ~/.bashrc

# For running from jupyter notebook
EXPOSE 8888
CMD ["conda", "run", "--no-capture-output", "-n", "pymc-dev-py39", "jupyter","notebook","--ip=0.0.0.0","--port=8888","--no-browser"]
42 changes: 0 additions & 42 deletions scripts/create_testenv.sh

This file was deleted.

24 changes: 24 additions & 0 deletions scripts/docker_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash

COMMAND="${1:-jupyter}"
SRC_DIR=${SRC_DIR:-`pwd`}
CONTAINER_NAME=${CONTAINER_NAME:-pymc}
PORT=${PORT:-8888}

# stop and remove previous instances of the pymc container to avoid naming conflicts
if [[ $(docker ps -aq -f name=${CONTAINER_NAME}) ]]; then
echo "Shutting down and removing previous instance of ${CONTAINER_NAME} container..."
docker rm -f ${CONTAINER_NAME}
fi

# $COMMAND can be either `build` or `bash` or `jupyter`
if [[ $COMMAND = 'build' ]]; then
docker build \
-t ${CONTAINER_NAME} \
-f $SRC_DIR/scripts/Dockerfile $SRC_DIR

elif [[ $COMMAND = 'bash' ]]; then
docker run -it -v $SRC_DIR:/home/jovyan/work --rm --name ${CONTAINER_NAME} ${CONTAINER_NAME} bash
else
docker run -it -p $PORT:8888 -v $SRC_DIR:/home/jovyan/work --rm --name ${CONTAINER_NAME} ${CONTAINER_NAME}
fi
48 changes: 0 additions & 48 deletions scripts/install_miniconda.sh

This file was deleted.

32 changes: 0 additions & 32 deletions scripts/start_container.sh

This file was deleted.

0 comments on commit 0ba47b5

Please sign in to comment.