Skip to content

Commit 0ba47b5

Browse files
authored
Update dockerfile to PyMC v4 (#5881)
* 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
1 parent f9b749b commit 0ba47b5

File tree

7 files changed

+68
-165
lines changed

7 files changed

+68
-165
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,5 @@ Quick links
99
* [Pull request (PR) checklist](https://docs.pymc.io/en/latest/contributing/pr_checklist.html)
1010
* [Python style guide with pre-commit](https://docs.pymc.io/en/latest/contributing/python_style.html)
1111
* [Running the test suite](https://docs.pymc.io/en/latest/contributing/running_the_test_suite.html)
12+
* [Running PyMC in Docker](https://docs.pymc.io/en/latest/contributing/docker_container.html)
1213
* [Submitting a bug report or feature request](https://github.com/pymc-devs/pymc/issues)
13-
14-
<!-- Commented out because our Docker image is outdated/broken.
15-
## Developing in Docker
16-
17-
We have provided a Dockerfile which helps for isolating build problems, and local development.
18-
Install [Docker](https://www.docker.com/) for your operating system, clone this repo, then
19-
run `./scripts/start_container.sh`. This should start a local docker container called `pymc`,
20-
as well as a [`jupyter`](http://jupyter.org/) notebook server running on port 8888. The
21-
notebook should be opened in your browser automatically (you can disable this by passing
22-
`--no-browser`). The repo will be running the code from your local copy of `pymc`,
23-
so it is good for development.
24-
25-
You may also use it to run the test suite, with
26-
27-
```bash
28-
$ docker exec -it pymc bash # logon to the container
29-
$ cd ~/pymc/tests
30-
$ . ./../../scripts/test.sh # takes a while!
31-
```
32-
33-
This should be quite close to how the tests run on TravisCI.
34-
35-
If the container was started without opening the browser, you
36-
need the notebook instances token to work with the notebook. This token can be
37-
accessed with
38-
39-
```
40-
docker exec -it pymc jupyter notebook list
41-
```
42-
-->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(docker_container)=
2+
# Running PyMC in Docker
3+
4+
We have provided a Dockerfile which helps for isolating build problems, and local development.
5+
Install [Docker](https://www.docker.com/) for your operating system, clone this repo, then
6+
run the following commands to build a `pymc` docker image.
7+
8+
```bash
9+
cd pymc
10+
bash scripts/docker_container.sh build
11+
```
12+
13+
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.
14+
15+
```bash
16+
bash scripts/docker_container.sh bash # running the container with bash
17+
bash scripts/docker_container.sh jupyter # running the container with jupyter notebook
18+
```

scripts/Dockerfile

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
FROM jupyter/minimal-notebook
1+
FROM jupyter/base-notebook:python-3.9.12
22

3-
ARG SRC_DIR=.
3+
LABEL name="pymc"
4+
LABEL description="Environment for PyMC version 4"
45

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

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

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

18-
ENV PYTHONPATH $PYTHONPATH:"$HOME"
17+
# Fix PkgResourcesDeprecationWarning
18+
RUN pip install --upgrade --user setuptools==58.3.0
19+
20+
#Setup working folder
21+
WORKDIR /home/jovyan/work
22+
23+
# For running from bash
24+
SHELL ["/bin/bash","-c"]
25+
RUN echo "conda activate pymc-dev-py39" >> ~/.bashrc && \
26+
source ~/.bashrc
27+
28+
# For running from jupyter notebook
29+
EXPOSE 8888
30+
CMD ["conda", "run", "--no-capture-output", "-n", "pymc-dev-py39", "jupyter","notebook","--ip=0.0.0.0","--port=8888","--no-browser"]

scripts/create_testenv.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

scripts/docker_container.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /bin/bash
2+
3+
COMMAND="${1:-jupyter}"
4+
SRC_DIR=${SRC_DIR:-`pwd`}
5+
CONTAINER_NAME=${CONTAINER_NAME:-pymc}
6+
PORT=${PORT:-8888}
7+
8+
# stop and remove previous instances of the pymc container to avoid naming conflicts
9+
if [[ $(docker ps -aq -f name=${CONTAINER_NAME}) ]]; then
10+
echo "Shutting down and removing previous instance of ${CONTAINER_NAME} container..."
11+
docker rm -f ${CONTAINER_NAME}
12+
fi
13+
14+
# $COMMAND can be either `build` or `bash` or `jupyter`
15+
if [[ $COMMAND = 'build' ]]; then
16+
docker build \
17+
-t ${CONTAINER_NAME} \
18+
-f $SRC_DIR/scripts/Dockerfile $SRC_DIR
19+
20+
elif [[ $COMMAND = 'bash' ]]; then
21+
docker run -it -v $SRC_DIR:/home/jovyan/work --rm --name ${CONTAINER_NAME} ${CONTAINER_NAME} bash
22+
else
23+
docker run -it -p $PORT:8888 -v $SRC_DIR:/home/jovyan/work --rm --name ${CONTAINER_NAME} ${CONTAINER_NAME}
24+
fi

scripts/install_miniconda.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

scripts/start_container.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)