Skip to content

Commit

Permalink
Merge pull request #116 from robertapplin/101_CreateDockerfile
Browse files Browse the repository at this point in the history
Create Ubuntu Dockerfile for the project
  • Loading branch information
robertapplin authored Feb 6, 2022
2 parents 5129980 + e384831 commit 314d337
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#####
## 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. 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 && \
rm -rf /var/lib/apt/lists/*

# 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
61 changes: 61 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## 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 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 .
```

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
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
```
1 change: 1 addition & 0 deletions docker/config/default-display-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/sbin/lightdm
8 changes: 8 additions & 0 deletions docker/config/lightdm.conf
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 314d337

Please sign in to comment.