|
1 | | -## Dockerfile |
2 | | -# This container provides a complete run-time environment for SimulaQron. |
3 | | -# |
4 | | -## Build: |
5 | | -# From inside the top-level SimulaQron directory run |
6 | | -# |
7 | | -# docker build -t <image_name> . |
8 | | -# |
9 | | -# where you should replace <image_name> with the name you want to give to the |
10 | | -# docker image. |
11 | | -# |
12 | | -## Run: |
13 | | -# To start the container and enter the shell prompt inside, run |
14 | | -# |
15 | | -# docker run -it <image_name> |
16 | | -# |
17 | | -# This will start a docker container with SimulaQron inside the |
18 | | -# /workspace/SimulaQron directory (this default can be changed, by changing the |
19 | | -# WORKSPACE variable in this file). Note that this is only a COPY of the |
20 | | -# SimulaQron directory that was made during the build step so if you make any |
21 | | -# changes on the host system, they will not be reflected in the container until |
22 | | -# you rebuild the image. |
23 | | -# |
24 | | -# However, if you wish, you can mount the host's SimulaQron directory into the |
25 | | -# container rather than using a copy made during the build step, you need to |
26 | | -# explicitly mount it when starting the container, e.g. |
27 | | -# |
28 | | -# docker run -it -v /path/to/SimulaQron:/workspace/SimulaQron <image_name> |
29 | | -# |
30 | | -# This will mount /path/to/SimulaQron inside the container in |
31 | | -# /workspace/SimulaQron. Note that on Linux systems with SELinux present, the |
32 | | -# mount option has to be `-v /path/to/SimulaQron:/workspace/SimulaQron:z`. |
33 | | -# |
34 | | -## Multiple shells: |
35 | | -# To attach to a running container with a new shell run |
36 | | -# |
37 | | -# docker exec -it <container_name> bash |
38 | | -# |
39 | | -# where <container_name> is the name of the running container (this is in |
40 | | -# general not the same as the image name). To find what name your container |
41 | | -# has, run `docker ps`. |
42 | | - |
43 | | -FROM ubuntu:18.04 |
44 | | -LABEL author="Wojciech Kozlowski <w.kozlowski@tudelft.nl>" |
45 | | - |
46 | | -# Update docker image |
47 | | -ENV DEBIAN_FRONTEND=noninteractive |
48 | | -RUN apt-get update && apt-get upgrade -y |
49 | | - |
50 | | -# Install Python 3 |
51 | | -RUN apt-get install -y python3 python3-pip python3-tk |
52 | | - |
53 | | -# Set a UTF-8 locale - this is needed for some python packages to play nice |
54 | | -RUN apt-get -y install language-pack-en |
55 | | -ENV LANG="en_US.UTF-8" |
56 | | - |
57 | | -RUN pip3 install simulaqron |
| 1 | +# If you need a slim version, use "alpine" base instead of trixie (Debian) |
| 2 | +#FROM python:3.12-alpine AS base-image |
| 3 | +FROM ubuntu:24.04 AS base-image |
| 4 | + |
| 5 | +# Install packages |
| 6 | + |
| 7 | +#RUN apk add --no-cache bash vim nano libstdc++ libgomp |
| 8 | +RUN apt-get update |
| 9 | +RUN apt-get dist-upgrade -y |
| 10 | +RUN apt-get install -y bash vim nano libgomp1 adduser git openssl make software-properties-common |
| 11 | + |
| 12 | +RUN add-apt-repository ppa:deadsnakes/ppa |
| 13 | +RUN apt-get update |
| 14 | + |
| 15 | +# Install Python 3.12 |
| 16 | +RUN apt-get install -y python3.12-full python3.12-dev |
| 17 | + |
| 18 | +# Switch to Bash |
| 19 | +SHELL ["/bin/bash", "-c"] |
| 20 | + |
| 21 | +# Delete the build-in user - not needed in alpine images |
| 22 | +RUN userdel -r ubuntu |
| 23 | + |
| 24 | +# Create student user |
| 25 | +ARG GNAME=student |
| 26 | +ARG GID=1000 |
| 27 | +ARG UNAME=student |
| 28 | +ARG UID=1000 |
| 29 | +ARG UHOME=/home/student |
| 30 | +ENV HOME=${UHOME} |
| 31 | +RUN set -o errexit -o nounset |
| 32 | +RUN addgroup --gid ${GID} "${GNAME}" |
| 33 | +RUN adduser --home "${UHOME}" --disabled-password --uid ${UID} --ingroup "${GNAME}" "${UNAME}" |
| 34 | +WORKDIR ${UHOME} |
| 35 | + |
| 36 | +# Remove unnecessary sotware |
| 37 | +RUN apt-get purge -y adduser software-properties-common |
| 38 | +RUN apt-get autoremove -y |
| 39 | + |
| 40 | +FROM base-image AS venv-image |
| 41 | + |
| 42 | + |
| 43 | +# Install build essentials, to correctly build python deps |
| 44 | +# We install it only for this stage, so we create a lighter docker image for executing |
| 45 | +#RUN apk add --no-cache alpine-sdk |
| 46 | +RUN apt-get update |
| 47 | +RUN apt-get install -y build-essential cmake linux-headers-generic |
| 48 | + |
| 49 | +# Create python virtual environment |
| 50 | +WORKDIR ${UHOME} |
| 51 | +RUN python3.12 -m venv simulaqron-venv |
| 52 | +# We have to "manually" activate the virtual environment |
| 53 | +ENV PATH="${UHOME}/simulaqron-venv/bin:$PATH" |
| 54 | + |
| 55 | +# Install SimulaQron |
| 56 | +# Option 1: Install from the wheel file |
| 57 | +# Copy the simulaqron wheel into the container |
| 58 | +COPY dist/*.whl ${UHOME} |
| 59 | +RUN pip install *.whl |
| 60 | +RUN rm *.whl |
| 61 | + |
| 62 | +# Install extra packages that need build-essential |
| 63 | +RUN pip install "qutip<5.0.0" |
| 64 | +RUN pip install "setuptools<81" pybind11 |
| 65 | +RUN pip install "git+https://github.com/ProjectQ-Framework/ProjectQ.git@v0.8.0" --no-build-isolation |
| 66 | + |
| 67 | +# Option 2: (Recommended for release) Install from PyPI |
| 68 | +#RUN pip install "simulaqron[opt]>=4.0.1" |
| 69 | + |
| 70 | +FROM base-image AS run-image |
| 71 | + |
| 72 | +# Copy installed python packages from previous image |
| 73 | +COPY --from=venv-image --chown=${UNAME} ${UHOME}/simulaqron-venv "${UHOME}/.local" |
| 74 | +# Since these files come from a python virtual environment |
| 75 | +# we need to fix some absolute paths |
| 76 | +WORKDIR ${UHOME}/.local/bin |
| 77 | +RUN sed -i "s|${UHOME}/simulaqron-venv/|${UHOME}/.local/|g" * |
| 78 | +# Activate the "virtual environment" we just copied |
| 79 | +ENV PATH="${UHOME}/.local/bin:${UHOME}/.local:$PATH" |
| 80 | + |
| 81 | +# Configure libgomp to use a single thread to avoid deadlocks in simulaqron |
| 82 | +ENV OMP_NUM_THREADS=1 |
| 83 | + |
| 84 | +# Switch to user student |
| 85 | +USER student |
| 86 | +WORKDIR ${UHOME} |
| 87 | +RUN echo 'export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "' >> ~/.bashrc |
| 88 | + |
| 89 | +CMD bash |
0 commit comments