From d224261c0ff2bd9e95caeab22bd1ff566cad6bc7 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Sun, 30 Jan 2022 19:04:38 +0000 Subject: [PATCH 01/10] Refs #101. Create a Dockerfile. --- docker/Dockerfile | 51 +++++++++++++++++++++++++++++++++++++++++++++++ docker/start.py | 3 +++ 2 files changed, 54 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/start.py diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..b8142ffc --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,51 @@ +##### +## Docker image for N-Body-Simulations +##### + +# Install the Ubuntu latest base image +FROM ubuntu:latest + +# To avoid user interaction during the installation of cmake +ARG DEBIAN_FRONTEND=noninteractive + +# Create git repository variable +ARG GIT_REPOSITORY=https://github.com/robertapplin/N-Body-Simulations + +# Install packages required in the container environment +RUN apt-get update && \ + apt-get install -y cmake git ffmpeg libsm6 libxcb-xinerama0 libxext6 libglib2.0-0 lightdm python3.8 python3-pip python3-venv + +RUN echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager +RUN echo "\ +[LightDM]\n\ +[Seat:*]\n\ +type=xremote\n\ +xserver-hostname=host.docker.internal\n\ +xserver-display-number=0\n\ +autologin-user=root\n\ +autologin-user-timeout=0\n\ +autologin-session=Lubuntu\n\ +" > /etc/lightdm/lightdm.conf.d/lightdm.conf + +ENV DISPLAY=host.docker.internal:0.0 + +# Install the virtualenv python package +RUN python3 -m pip install --user virtualenv + +# Create a virtual environment +RUN cd /opt && \ + python3 -m venv env + +# Clone the N-Body-Simulations repository +RUN cd /usr && \ + git clone $GIT_REPOSITORY + +# Activate python environment, and install the N-Body-Simulations package +RUN . /opt/env/bin/activate && \ + cd /usr/N-Body-Simulations && \ + pip install -r requirements.txt && \ + python3 setup.py install + +CMD service dbus start; service lightdm start + +CMD [".", "/opt/env/bin/activate", "&&", "python3", "./usr/start.py"] diff --git a/docker/start.py b/docker/start.py new file mode 100644 index 00000000..b8500ddf --- /dev/null +++ b/docker/start.py @@ -0,0 +1,3 @@ +from n_body_simulations.startup import startup_widget + +startup_widget() From 69a404f2e33b0558dca834be61f8d526e14ba950 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Tue, 1 Feb 2022 20:07:43 +0000 Subject: [PATCH 02/10] Refs #101. Activate environment and start widget. --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index b8142ffc..e639ddeb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -48,4 +48,4 @@ RUN . /opt/env/bin/activate && \ CMD service dbus start; service lightdm start -CMD [".", "/opt/env/bin/activate", "&&", "python3", "./usr/start.py"] +CMD . /opt/env/bin/activate && python3 /usr/start.py From 87f2d95e2d1c9e893334689ed145d5f912662965 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Tue, 1 Feb 2022 21:36:46 +0000 Subject: [PATCH 03/10] Refs #101. Remove unrequired library downloads. --- docker/Dockerfile | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e639ddeb..aff82cd1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,23 +11,12 @@ ARG DEBIAN_FRONTEND=noninteractive # Create git repository variable ARG GIT_REPOSITORY=https://github.com/robertapplin/N-Body-Simulations +# Set the DISPLAY variable to be available at runtime +ENV DISPLAY=host.docker.internal:0.0 + # Install packages required in the container environment RUN apt-get update && \ - apt-get install -y cmake git ffmpeg libsm6 libxcb-xinerama0 libxext6 libglib2.0-0 lightdm python3.8 python3-pip python3-venv - -RUN echo "/usr/sbin/lightdm" > /etc/X11/default-display-manager -RUN echo "\ -[LightDM]\n\ -[Seat:*]\n\ -type=xremote\n\ -xserver-hostname=host.docker.internal\n\ -xserver-display-number=0\n\ -autologin-user=root\n\ -autologin-user-timeout=0\n\ -autologin-session=Lubuntu\n\ -" > /etc/lightdm/lightdm.conf.d/lightdm.conf - -ENV DISPLAY=host.docker.internal:0.0 + apt-get install -y cmake git libxcb-xinerama0 lightdm python3.8 python3-pip python3-venv # Install the virtualenv python package RUN python3 -m pip install --user virtualenv @@ -46,6 +35,6 @@ RUN . /opt/env/bin/activate && \ pip install -r requirements.txt && \ python3 setup.py install -CMD service dbus start; service lightdm start - -CMD . /opt/env/bin/activate && python3 /usr/start.py +# Activate python environment, and startup the widget +CMD . /opt/env/bin/activate && \ + python3 /usr/N-Body-Simulations/n_body_simulations/startup.py From c13450e2da980593d938a8f058f9b388da7b77b5 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Tue, 1 Feb 2022 21:40:05 +0000 Subject: [PATCH 04/10] Refs #101. Add docker-mountable config files. --- docker/config/default-display-manager | 1 + docker/config/lightdm.conf | 8 ++++++++ docker/start.py | 3 --- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 docker/config/default-display-manager create mode 100644 docker/config/lightdm.conf delete mode 100644 docker/start.py diff --git a/docker/config/default-display-manager b/docker/config/default-display-manager new file mode 100644 index 00000000..7d4e29bb --- /dev/null +++ b/docker/config/default-display-manager @@ -0,0 +1 @@ +/usr/sbin/lightdm diff --git a/docker/config/lightdm.conf b/docker/config/lightdm.conf new file mode 100644 index 00000000..28c374c5 --- /dev/null +++ b/docker/config/lightdm.conf @@ -0,0 +1,8 @@ +[LightDM] +[Seat:*] +type=xremote +xserver-hostname=host.docker.internal +xserver-display-number=0 +autologin-user=root +autologin-user-timeout=0 +autologin-session=Lubuntu diff --git a/docker/start.py b/docker/start.py deleted file mode 100644 index b8500ddf..00000000 --- a/docker/start.py +++ /dev/null @@ -1,3 +0,0 @@ -from n_body_simulations.startup import startup_widget - -startup_widget() From 9b9895e7622695933304494d01728d93d6486d3f Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Tue, 1 Feb 2022 22:10:34 +0000 Subject: [PATCH 05/10] Refs #101. Add README for docker usage. --- docker/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..b854cd2e --- /dev/null +++ b/docker/README.md @@ -0,0 +1,23 @@ +## Docker Container + +This document provides a guide for building the ``Dockerfile`` in this repository, and then running the N-Body Simulations widget within a container from Windows. You will need to install [Xming X Server for Windows](https://sourceforge.net/projects/xming/) before continuing with this guide, as well as [Docker Desktop](https://docs.docker.com/desktop/windows/install/). You might also need to ``pip install winpty``. + +Firstly, make sure you have your command prompt open in the ``docker`` directory: + +```sh +cd docker/ +``` + +Start the Docker Daemon, and then build the ``Dockerfile`` with tag ``n-body-simulations``: + +```sh +docker build --no-cache -t n-body-simulations . +``` + +After the build has finished, start Xming X Server with the default settings. Run the image and mount the config files into the container: + +```sh +winpty docker run -u=root -it --mount "type=bind,source=$PWD/config/lightdm.conf,target=/etc/lightdm/lightdm.conf.d/lightdm.conf" --mount "type=bind,source=$PWD/config/default-display-manager,target=/etc/X11/default-display-manager" n-body-simulations:latest +``` + +The N-Body Simulations widget should open within an containerized Ubuntu environment. From 7fb3c9954c15a0dc882bdb3bdc4ca250ee240d87 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Tue, 1 Feb 2022 22:11:02 +0000 Subject: [PATCH 06/10] Refs #101. Remove warning by setting environment variable. --- docker/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index aff82cd1..8ffa70bc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,6 +14,9 @@ ARG GIT_REPOSITORY=https://github.com/robertapplin/N-Body-Simulations # Set the DISPLAY variable to be available at runtime ENV DISPLAY=host.docker.internal:0.0 +# Set the XDG_RUNTIME_DIR variable to its default to avoid a warning +ENV XDG_RUNTIME_DIR=/tmp/runtime-root + # Install packages required in the container environment RUN apt-get update && \ apt-get install -y cmake git libxcb-xinerama0 lightdm python3.8 python3-pip python3-venv From 6272e066685dc345c335b6a2dd70b9ac11618dd3 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Sat, 5 Feb 2022 00:55:48 +0000 Subject: [PATCH 07/10] Refs #101. Add a docker compose file. --- docker/Dockerfile | 12 +----------- docker/README.md | 32 ++++++++++++++++++++++++++++---- docker/docker-compose.yml | 22 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 docker/docker-compose.yml diff --git a/docker/Dockerfile b/docker/Dockerfile index 8ffa70bc..aae84be9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,15 +11,9 @@ ARG DEBIAN_FRONTEND=noninteractive # Create git repository variable ARG GIT_REPOSITORY=https://github.com/robertapplin/N-Body-Simulations -# Set the DISPLAY variable to be available at runtime -ENV DISPLAY=host.docker.internal:0.0 - -# Set the XDG_RUNTIME_DIR variable to its default to avoid a warning -ENV XDG_RUNTIME_DIR=/tmp/runtime-root - # Install packages required in the container environment RUN apt-get update && \ - apt-get install -y cmake git libxcb-xinerama0 lightdm python3.8 python3-pip python3-venv + apt-get install -y cmake git libgl1-mesa-glx libxcb-xinerama0 lightdm mesa-utils python3.8 python3-pip python3-venv # Install the virtualenv python package RUN python3 -m pip install --user virtualenv @@ -37,7 +31,3 @@ RUN . /opt/env/bin/activate && \ cd /usr/N-Body-Simulations && \ pip install -r requirements.txt && \ python3 setup.py install - -# Activate python environment, and startup the widget -CMD . /opt/env/bin/activate && \ - python3 /usr/N-Body-Simulations/n_body_simulations/startup.py diff --git a/docker/README.md b/docker/README.md index b854cd2e..f39c548d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -8,16 +8,40 @@ Firstly, make sure you have your command prompt open in the ``docker`` directory cd docker/ ``` -Start the Docker Daemon, and then build the ``Dockerfile`` with tag ``n-body-simulations``: +Start the Docker Daemon, and start an Xming X Server with the default settings. There is now two avenues for building the image and running a container as explained below. + +### Using the Dockerfile + +Build the ``Dockerfile`` with tag ``n-body-simulations``: ```sh docker build --no-cache -t n-body-simulations . ``` -After the build has finished, start Xming X Server with the default settings. Run the image and mount the config files into the container: +Then run the image and mount the config files into the container: + +```sh +winpty docker run -u=root -it -e DISPLAY=host.docker.internal:0.0 -e LIBGL_ALWAYS_INDIRECT=1 -e XDG_RUNTIME_DIR=/tmp/runtime-root \ +--mount "type=bind,source=$PWD/config/lightdm.conf,target=/etc/lightdm/lightdm.conf.d/lightdm.conf" \ +--mount "type=bind,source=$PWD/config/default-display-manager,target=/etc/X11/default-display-manager" \ +n-body-simulations:latest \ +bash -c ". /opt/env/bin/activate && python3 /usr/N-Body-Simulations/n_body_simulations/startup.py" +``` + +The N-Body Simulations widget should open within a containerized Ubuntu environment. + +### Using Docker Compose + +Build the ``n-body-simulations`` service seen in the ``docker-compose.yml`` file: + +```sh +docker-compose build n-body-simulations +``` + +Then simply run the container with the configuration seen in the ``docker-compose.yml`` file: ```sh -winpty docker run -u=root -it --mount "type=bind,source=$PWD/config/lightdm.conf,target=/etc/lightdm/lightdm.conf.d/lightdm.conf" --mount "type=bind,source=$PWD/config/default-display-manager,target=/etc/X11/default-display-manager" n-body-simulations:latest +docker-compose run --rm n-body-simulations ``` -The N-Body Simulations widget should open within an containerized Ubuntu environment. +The N-Body Simulations widget should open within a containerized Ubuntu environment. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..c27db6db --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.8" + +services: + n-body-simulations: + container_name: N-Body Simulations + image: n-body-simulations + build: + context: . + dockerfile: Dockerfile + environment: + - DISPLAY=host.docker.internal:0.0 + - LIBGL_ALWAYS_INDIRECT=1 + - XDG_RUNTIME_DIR=/tmp/runtime-root + volumes: + - type: bind + source: ./config/lightdm.conf + target: /etc/lightdm/lightdm.conf.d/lightdm.conf + - type: bind + source: ./config/default-display-manager + target: /etc/X11/default-display-manager + command: + bash -c ". /opt/env/bin/activate && python3 /usr/N-Body-Simulations/n_body_simulations/startup.py" From ce4f807ba2258af6d1270a8631b0e49ceecad9c4 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Sat, 5 Feb 2022 14:04:19 +0000 Subject: [PATCH 08/10] Clean up the apt cache after installation. --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index aae84be9..36ba5396 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,9 +11,10 @@ ARG DEBIAN_FRONTEND=noninteractive # Create git repository variable ARG GIT_REPOSITORY=https://github.com/robertapplin/N-Body-Simulations -# Install packages required in the container environment +# Install packages required in the container environment. Then clean up the apt cache RUN apt-get update && \ - apt-get install -y cmake git libgl1-mesa-glx libxcb-xinerama0 lightdm mesa-utils python3.8 python3-pip python3-venv + apt-get install -y cmake git libgl1-mesa-glx libxcb-xinerama0 lightdm mesa-utils python3.8 python3-pip python3-venv && \ + rm -rf /var/lib/apt/lists/* # Install the virtualenv python package RUN python3 -m pip install --user virtualenv From d5df6c7561b8b9e09d25bc919e7ae979efaa1c33 Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Sat, 5 Feb 2022 18:48:46 +0000 Subject: [PATCH 09/10] Refs #101. Add docs for pulling a dockerhub image. --- docker/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docker/README.md b/docker/README.md index f39c548d..677890f5 100644 --- a/docker/README.md +++ b/docker/README.md @@ -45,3 +45,17 @@ docker-compose run --rm n-body-simulations ``` The N-Body Simulations widget should open within a containerized Ubuntu environment. + +### Pulling from Dockerhub + +There is also the option to pull the image from [Dockerhub](https://hub.docker.com/r/robertapplin/n-body-simulations). + +```sh +docker pull robertapplin/n-body-simulations +``` + +You would then need to change the tag on the image so that it can be picked up by the ``docker-compose.yml`` file. + +```sh +docker tag robertapplin/n-body-simulations n-body-simulations +``` From e384831177fb9e6e70746cae1e84b887f45f824d Mon Sep 17 00:00:00 2001 From: Robert Applin Date: Sat, 5 Feb 2022 18:52:16 +0000 Subject: [PATCH 10/10] Refs #101. Fix indentation in Dockerfile. --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 36ba5396..19a8c3f3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -30,5 +30,5 @@ RUN cd /usr && \ # Activate python environment, and install the N-Body-Simulations package RUN . /opt/env/bin/activate && \ cd /usr/N-Body-Simulations && \ - pip install -r requirements.txt && \ - python3 setup.py install + pip install -r requirements.txt && \ + python3 setup.py install