Skip to content

Commit 0d9dbcd

Browse files
committed
Add Dockerfile for containerizing specified prebuilt release.
1 parent a5bb9af commit 0d9dbcd

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed

docker/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM python:3.7.5-buster
2+
COPY . /app
3+
WORKDIR /app
4+
RUN pip install -r requirements.txt --no-cache-dir

docker/README.md

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
# Snap-Python Docker
2+
Creates a lightweight Docker compute stack for performing network graph analysis using snap-python, numpy, and matplotlib agnostic of the host operating system.
3+
4+
This document stipulates installation requirements for the Docker Community Edition (CE), and walks through Docker installation, building, and running the snap-python Docker image.
5+
6+
## OS Requirements
7+
8+
Basic operating system requirements for running the Docker Engine - Community. See more at: [https://docs.docker.com/install/](https://docs.docker.com/install/).
9+
10+
### Linux
11+
12+
* **CentOS**
13+
* A maintained version of CentOS 7 is required for Docker Engine - Community
14+
* **Debian**
15+
* To install Docker Engine - Community, you need the 64-bit version of one of these Debian or Raspbian versions:
16+
* Buster 10
17+
* Stretch 9 (stable) / Raspbian Stretch
18+
* **Fedora**
19+
* To install Docker Engine - Community, you need the 64-bit version of one of these Fedora versions:
20+
* 28
21+
* 29
22+
* **Ubuntu**
23+
* To install Docker Engine - Community, you need the 64-bit version of one of these Ubuntu versions:
24+
* Disco 19.04
25+
* Cosmic 18.10
26+
* Bionic 18.04 (LTS)
27+
* Xenial 16.04 (LTS)
28+
29+
### macOS
30+
Your macOS hardware must meet the following requirements to install Docker Desktop. See more at: [https://docs.docker.com/docker-for-mac/install/](https://docs.docker.com/docker-for-mac/install/).
31+
32+
* Mac hardware must be a 2010 or newer model, with Intel’s hardware support for memory management unit (MMU) virtualization, including Extended Page Tables (EPT) and Unrestricted Mode. You can check to see if your machine has this support by running the following command in a terminal: sysctl kern.hv_support
33+
34+
* macOS must be version 10.13 or newer. We recommend upgrading to the latest version of macOS.
35+
36+
* If you experience any issues after upgrading your macOS to version 10.15, you must install the latest version of Docker Desktop to be compatible with this version of macOS.
37+
38+
* Note: Docker supports Docker Desktop on the most recent versions of macOS. That is, the current release of macOS and the previous two releases. As new major versions of macOS are made generally available, Docker will stop supporting the oldest version and support the newest version of macOS (in addition to the previous two releases).
39+
40+
* At least 4 GB of RAM.
41+
42+
* VirtualBox prior to version 4.3.30 must not be installed as it is not compatible with Docker Desktop.
43+
44+
### Windows
45+
System requirements:
46+
47+
* Windows 10 64-bit: Pro, Enterprise, or Education (Build 15063 or later).
48+
Hyper-V and Containers Windows features must be enabled.
49+
50+
* The following hardware prerequisites are required to successfully run Client Hyper-V on Windows 10:
51+
* 64 bit processor with [Second Level Address Translation (SLAT)](http://en.wikipedia.org/wiki/Second_Level_Address_Translation)
52+
* 4GB system RAM
53+
* BIOS-level hardware virtualization support must be enabled in the BIOS settings. For more information, see [Virtualization](https://docs.docker.com/docker-for-windows/troubleshoot/#virtualization-must-be-enabled)
54+
55+
## Docker Installation
56+
57+
Note that installation steps outlined below for Linux are purposefully only defined for Ubuntu. Installation of Docker for other Linux distributions is left as an exercise to the reader. These instructions outline installation from the Docker repository (the recommended approach), and are a subset of the instructions available at [https://docs.docker.com/install/](https://docs.docker.com/install/).
58+
59+
#### Linux (Ubuntu)
60+
61+
1. Begin by updating all packages:
62+
63+
```
64+
$ sudo apt-get update
65+
```
66+
67+
2. It is recommended to uninstall any old Docker software before proceeding (note that this command accounts for old versions of Docker, which were named "docker", "docker.io", etc.):
68+
69+
```
70+
$ sudo apt-get remove docker docker-engine docker.io containerd runc
71+
```
72+
73+
3. Set up the Docker repository to install from:
74+
75+
```
76+
$ sudo apt-get install \
77+
apt-transport-https \
78+
ca-certificates \
79+
curl \
80+
gnupg-agent \
81+
software-properties-common
82+
```
83+
4. Add Docker's official GPG key:
84+
85+
```
86+
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
87+
```
88+
89+
5. Verify that you have the key with the fingerprint `9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88` by searching for the last 8 characters of the fingerprint:
90+
91+
```
92+
$ sudo apt-key fingerprint 0EBFCD88
93+
94+
pub rsa4096 2017-02-22 [SCEA]
95+
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
96+
uid [ unknown] Docker Release (CE deb) <[email protected]>
97+
sub rsa4096 2017-02-22 [S]
98+
```
99+
100+
6. Use the following command to setup the **stable** repository:
101+
102+
```
103+
$ sudo add-apt-repository \
104+
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
105+
$(lsb_release -cs) \
106+
stable"
107+
```
108+
109+
7. Install the latest version of Docker Engine - Community and containerd:
110+
111+
```
112+
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
113+
```
114+
115+
8. Verify that Docker Engine - Community is correctly installed by running the `hello-world` image:
116+
117+
```
118+
$ sudo docker run hello-world
119+
```
120+
121+
#### macOS
122+
To download Docker Desktop for macOS, go to [Docker Hub](https://hub.docker.com/?overlay=onboarding) and sign in with your DockerID. You will require a Docker Hub account. See more at [https://docs.docker.com/docker-for-mac/install/](https://docs.docker.com/docker-for-mac/install/).
123+
124+
1. Download the Docker Desktop installer for macOS from the link above
125+
2. Double-click the Docker.dmg to open the installer, then drag the Docker icon to the Applications folder
126+
3. Double-click Docker.app in the Applications folder to start Docker
127+
4. Verify the Docker daemon is running by running the `hello-world` image:
128+
129+
```
130+
$ docker run hello-world
131+
```
132+
133+
#### Windows
134+
To download Docker Desktop for Windows, go to [Docker Hub](https://hub.docker.com/?overlay=onboarding) and sign in with your DockerID. You will require a Docker Hub account. See more at [https://docs.docker.com/docker-for-windows/install/](https://docs.docker.com/docker-for-windows/install/).
135+
136+
1. Download the Docker Desktop installer for Windows from the link above
137+
2. Double click the **Docker Desktop Installer.exe** to run the installer
138+
3. Follow the instructions on the installation wizard to accept the license, authorize the installer, and proceed with the install
139+
* **Note:** When prompted, authorize the Docker Desktop Installer with your system password during the install process. Privileged access is needed to install networking components, links to the Docker apps, and manage the Hyper-V VMs
140+
4. Click **Finish** on the setup complete dialog and launch the Docker Desktop application.
141+
5. Verify the Docker daemon is running by running the `hello-world` image:
142+
143+
```
144+
$ docker run hello-world
145+
```
146+
147+
## Building the snap-python Docker image
148+
Once Docker is installed on your host, we can build the `snap-python` Docker image. The Docker image is a lightweight read-only template used to build containers, which are running "jailed" processes. We can build the `snap-python` image in one of two ways:
149+
150+
1. We can install directly from the hosted official image on Docker Hub (recommended):
151+
* ```$ docker pull cam2337/snap-python:latest```
152+
153+
154+
2. Alternatively, if you've cloned this repository (see installation instructions in the top-level `README.md`), we can build the Docker image directly from the `Dockerfile` in `<repository-root>/docker/`:
155+
* ```$ docker build . -t snap-python```
156+
157+
## Running a snap-python Docker container
158+
We can verify that the `snap-python` image is installed by issuing the following command:
159+
160+
```
161+
$ ctew-macbookpro:examples ctew$ docker images
162+
REPOSITORY TAG IMAGE ID CREATED SIZE
163+
cam2337/snap-python latest e2229d02c39e 46 minutes ago 1.09GB
164+
```
165+
166+
As we see from the example above, this image was downloaded and built from the official image as hosted on Docker Hub.
167+
168+
Now that the image is built, all we need to do is run a snap-python container:
169+
170+
```
171+
$ docker run -it cam2337/snap-python
172+
Python 3.7.5 (default, Nov 23 2019, 05:59:34)
173+
[GCC 8.3.0] on linux
174+
Type "help", "copyright", "credits" or "license" for more information.
175+
>>> import snap
176+
>>> snap.Version
177+
'5.0.0'
178+
```
179+
180+
While an interactive Python shell with `snap-python` capabilities is great, we can go one step further and specify a working directory for a python application that relies on snap. This directory can be mounted as [volume](https://docs.docker.com/storage/volumes/) in the snap-python Docker container. The scripts then have full access to the `snap-python` module that was baked into our image:
181+
182+
```
183+
docker run -it --rm -v "<working-directory>":/usr/src/snap -w /usr/src/snap cam2337/snap-python python <working-directory>/<example-python-file>
184+
```
185+
186+
Let's individually cover some of the more interesting components of this command:
187+
188+
* `-it`: This tells Docker that we want to run the container interactively, by keeping STDIN open even if not attached. It additionally allocates a pseudo-TTY
189+
* `--rm`: Instructs Docker to automatically remove the container once it exits. Since our Docker container is functioning as a "compute stack" (instead of, say, a server or backend), this is desirable, as there's no need for a container to be hanging around after we've run our application.
190+
* `-v`: Instructs Docker to mount the following local filesystem directory at `/usr/src/snap`
191+
* `-w`: Instructs Docker that its working directory should be the newly-mounted volume at `/usr/src/snap`
192+
* `cam2337/snap-python`: The image we want to run
193+
* `python`: The command we want to issue once our container is started
194+
* `<working-directory>/<example-python-file>`: The python file from our local filesystem to run in the `snap-python` container
195+
196+
197+
## Frequently Asked Questions (FAQ)
198+
199+
### Q: My Python application has specific package requirements. How can I build my own custom Docker image that installs these additional packages?
200+
You can leverage the image created by the `Dockerfile` in this directory (or hosted on [Docker Hub](https://hub.docker.com/repository/docker/cam2337/snap-python)) and build upon it in [layers](https://docs.docker.com/v17.09/engine/userguide/storagedriver/imagesandcontainers/#images-and-layers). Say, for instance, you need `pandas` installed for your Python application to work. An example Dockerfile might look like:
201+
202+
```
203+
FROM cam2337/snap-python:latest
204+
RUN pip install pandas
205+
```
206+
207+
You can then build this image locally:
208+
209+
```
210+
$ docker build -t my-custom-snap-python .
211+
```
212+
213+
We can then run the container and verify that importing `pandas` behaves as expected:
214+
215+
```
216+
$ ctew-macbookpro:docker ctew$ docker run -it my-custom-snap-python
217+
Python 3.7.5 (default, Nov 23 2019, 05:59:34)
218+
[GCC 8.3.0] on linux
219+
Type "help", "copyright", "credits" or "license" for more information.
220+
>>> import pandas
221+
>>>
222+
```
223+
224+
### Q: How can I leverage the snap-python Docker compute stack from the comfort of my favorite editor?
225+
Most popular editors nowadays provide the option to create a custom "build system" for building/running a subset of files. In this way, they become more akin to a traditional integrated development environment (IDE). We can leverage this fact to create a custom build system for our snap-python Docker compute stack.
226+
227+
For example, we can create the following custom build system in SublimeText:
228+
229+
```
230+
{
231+
"shell_cmd": "docker run --rm -v $file_path:/usr/src/snap -w /usr/src/snap cam2337/snap-python python $file_name",
232+
"selector": "source.python",
233+
"file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)"
234+
}
235+
```
236+
237+
Saving this as `docker-snap-python.build` in the SublimeText user build system space, we can now select it from `Tools > Build System > docker-snap-python`. Building an in-focus Python file with this option selected will now execute our snap-python Docker compute stack.

docker/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cycler==0.10.0
2+
kiwisolver==1.1.0
3+
matplotlib==3.1.2
4+
numpy==1.17.4
5+
pyparsing==2.4.5
6+
python-dateutil==2.8.1
7+
six==1.13.0
8+
snap-stanford==5.0.0

0 commit comments

Comments
 (0)