Skip to content

Commit 08d013c

Browse files
authored
Merge pull request #13 from aunchagaonkar/main
Add Jupyter Lab Docker environment setup
2 parents c4d1804 + 1d5f4dc commit 08d013c

File tree

6 files changed

+358
-0
lines changed

6 files changed

+358
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ignore these files and directories when building the Docker image
2+
README.md
3+
.git
4+
.gitignore
5+
notebooks/*
6+
data/*
7+
scripts/*
8+
*.log
9+
.DS_Store
10+
Thumbs.db
11+
.env
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Use the official Jupyter base image with Python 3.11
2+
FROM jupyter/scipy-notebook:latest
3+
4+
# Set the working directory
5+
WORKDIR /home/user/work
6+
7+
# Switch to root to install system packages
8+
USER root
9+
10+
# Install additional system packages if needed
11+
RUN apt-get update && apt-get install -y \
12+
git \
13+
curl \
14+
wget \
15+
vim \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Switch back to user user
20+
USER user
21+
22+
# Install additional Python packages
23+
COPY requirements.txt /tmp/requirements.txt
24+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
25+
26+
# Create directories for notebooks and data
27+
RUN mkdir -p /home/user/work/notebooks \
28+
&& mkdir -p /home/user/work/data \
29+
&& mkdir -p /home/user/work/scripts
30+
31+
# Expose the Jupyter Lab port
32+
EXPOSE 8888
33+
34+
# Set environment variables
35+
ENV JUPYTER_ENABLE_LAB=yes
36+
ENV JUPYTER_TOKEN=""
37+
38+
# Start Jupyter Lab
39+
CMD ["start-notebook.sh", "--NotebookApp.token=''", "--NotebookApp.password=''"]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Jupyter Lab Docker Setup
2+
3+
This directory contains a complete Docker setup for running Jupyter Lab with a comprehensive data science and machine learning environment.
4+
5+
## What's Included
6+
7+
- **Jupyter Lab** - Latest version with lab interface
8+
- **Python 3.11** - Latest stable Python version
9+
- **Data Science Libraries**:
10+
- NumPy, Pandas, Matplotlib, Seaborn, Plotly
11+
- Scikit-learn, TensorFlow, PyTorch
12+
- Scipy, Bokeh, Altair
13+
- **Development Tools**:
14+
- Git, Jupyter extensions
15+
- Black formatter, Flake8 linter, Pytest
16+
- **Utilities**: Requests, BeautifulSoup, Excel support
17+
18+
## Quick Start
19+
20+
### Using Docker Compose (Recommended)
21+
22+
1. **Start Jupyter Lab**:
23+
```bash
24+
docker-compose up -d
25+
```
26+
27+
2. **Access Jupyter Lab**:
28+
Open your browser and go to: http://localhost:8888
29+
30+
3. **Stop the service**:
31+
```bash
32+
docker-compose down
33+
```
34+
35+
### Using Docker directly
36+
37+
1. **Build the image**:
38+
```bash
39+
docker build -t jupyter-lab-ml .
40+
```
41+
42+
2. **Run the container**:
43+
```bash
44+
docker run -p 8888:8888 -v $(pwd)/notebooks:/home/user/work/notebooks jupyter-lab-ml
45+
```
46+
47+
## Directory Structure
48+
49+
```
50+
Python-ML-Development/
51+
├── Dockerfile # Docker image definition
52+
├── docker-compose.yml # Docker Compose configuration
53+
├── requirements.txt # Python package dependencies
54+
├── README.md # This file
55+
├── notebooks/ # Your Jupyter notebooks (mounted volume)
56+
├── data/ # Data files (mounted volume)
57+
└── scripts/ # Python scripts (mounted volume)
58+
```
59+
60+
## Features
61+
62+
- **No Authentication**: Set up for development use (no token/password required)
63+
- **Persistent Storage**: Your notebooks, data, and scripts are saved on your host machine
64+
- **Auto-restart**: Container restarts automatically unless stopped manually
65+
- **Full Lab Interface**: Modern Jupyter Lab interface with extensions
66+
- **Git Integration**: Git is pre-installed for version control
67+
68+
## Security Note
69+
70+
This setup is configured for development use with no authentication. Do not expose this to the internet or use in production without proper security measures.
71+
72+
## Customization
73+
74+
- **Add packages**: Edit `requirements.txt` and rebuild the image
75+
- **Change port**: Modify the port mapping in `docker-compose.yml`
76+
- **Add system packages**: Edit the `Dockerfile` to install additional system dependencies
77+
78+
## Troubleshooting
79+
80+
- **Port already in use**: Change the port in `docker-compose.yml` from `8888:8888` to `8889:8888`
81+
- **Permission issues**: Make sure Docker has access to the project directory
82+
- **Container won't start**: Check logs with `docker-compose logs jupyter-lab`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3.8'
2+
3+
services:
4+
jupyter-lab:
5+
build: .
6+
container_name: jupyter-lab-ml
7+
ports:
8+
- "8888:8888"
9+
volumes:
10+
- ./notebooks:/home/user/work/notebooks
11+
- ./data:/home/user/work/data
12+
- ./scripts:/home/user/work/scripts
13+
environment:
14+
- JUPYTER_ENABLE_LAB=yes
15+
- JUPYTER_TOKEN=""
16+
- GRANT_SUDO=yes
17+
restart: unless-stopped
18+
working_dir: /home/user/work
19+
command: start-notebook.sh --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_root=True
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "9ad8eae8",
6+
"metadata": {},
7+
"source": [
8+
"# Welcome to Jupyter Lab Docker Environment\n",
9+
"\n",
10+
"This is a sample notebook to help you get started with your new Jupyter Lab environment."
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "f7f48161",
16+
"metadata": {},
17+
"source": [
18+
"## 1. Testing Python Environment"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "417706d5",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"import sys\n",
29+
"print(f\"Python version: {sys.version}\")\n",
30+
"print(f\"Python executable: {sys.executable}\")"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"id": "c2e241b1",
36+
"metadata": {},
37+
"source": [
38+
"## 2. Testing Data Science Libraries"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"id": "e06ce4a6",
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"# Import essential libraries\n",
49+
"import numpy as np\n",
50+
"import pandas as pd\n",
51+
"import matplotlib.pyplot as plt\n",
52+
"import seaborn as sns\n",
53+
"\n",
54+
"print(\"NumPy version:\", np.__version__)\n",
55+
"print(\"Pandas version:\", pd.__version__)\n",
56+
"print(\"Matplotlib and Seaborn imported successfully\")"
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"id": "0e8e326e",
62+
"metadata": {},
63+
"source": [
64+
"## 3. Simple Data Visualization Example"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"id": "6f253828",
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"np.random.seed(42)\n",
75+
"data = {\n",
76+
" 'x': np.random.randn(100),\n",
77+
" 'y': np.random.randn(100),\n",
78+
" 'category': np.random.choice(['A', 'B', 'C'], 100)\n",
79+
"}\n",
80+
"df = pd.DataFrame(data)\n",
81+
"\n",
82+
"# Create a simple plot\n",
83+
"plt.figure(figsize=(10, 6))\n",
84+
"sns.scatterplot(data=df, x='x', y='y', hue='category')\n",
85+
"plt.title('Sample Scatter Plot')\n",
86+
"plt.show()\n",
87+
"\n",
88+
"print(\"Visualization working correctly!\")"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "5e866e79",
94+
"metadata": {},
95+
"source": [
96+
"## 4. Testing Machine Learning Libraries"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"id": "2dd1055b",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"from sklearn.datasets import make_classification\n",
107+
"from sklearn.model_selection import train_test_split\n",
108+
"from sklearn.ensemble import RandomForestClassifier\n",
109+
"from sklearn.metrics import accuracy_score\n",
110+
"\n",
111+
"X, y = make_classification(n_samples=1000, n_features=4, n_classes=2, random_state=42)\n",
112+
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
113+
"\n",
114+
"model = RandomForestClassifier(random_state=42)\n",
115+
"model.fit(X_train, y_train)\n",
116+
"\n",
117+
"predictions = model.predict(X_test)\n",
118+
"accuracy = accuracy_score(y_test, predictions)\n",
119+
"\n",
120+
"print(f\"Model accuracy: {accuracy:.3f}\")\n",
121+
"print(\"Scikit-learn working correctly!\")"
122+
]
123+
},
124+
{
125+
"cell_type": "markdown",
126+
"id": "e60a9faf",
127+
"metadata": {},
128+
"source": [
129+
"## 5. Environment Information"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "2dc9777d",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"import subprocess\n",
140+
"import sys\n",
141+
"\n",
142+
"result = subprocess.run([sys.executable, '-m', 'pip', 'list'], \n",
143+
" capture_output=True, text=True)\n",
144+
"print(\"Installed packages:\")\n",
145+
"print(result.stdout)"
146+
]
147+
},
148+
{
149+
"cell_type": "markdown",
150+
"id": "a10236fb",
151+
"metadata": {},
152+
"source": [
153+
"## Next Steps\n",
154+
"\n",
155+
"Your Jupyter Lab environment is ready! Here's what you can do:\n",
156+
"\n",
157+
"1. **Create new notebooks** in the `notebooks/` directory\n",
158+
"2. **Add data files** to the `data/` directory\n",
159+
"3. **Write Python scripts** in the `scripts/` directory\n",
160+
"4. **Install additional packages** by adding them to `requirements.txt` and rebuilding the Docker image\n",
161+
"\n",
162+
"Happy coding! 🚀"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"language_info": {
168+
"name": "python"
169+
}
170+
},
171+
"nbformat": 4,
172+
"nbformat_minor": 5
173+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Core data science packages
2+
numpy==1.24.3
3+
pandas==2.0.3
4+
matplotlib==3.7.2
5+
seaborn==0.12.2
6+
plotly==5.15.0
7+
scipy==1.11.1
8+
9+
# Machine learning libraries
10+
scikit-learn==1.3.0
11+
tensorflow==2.13.0
12+
torch==2.0.1
13+
torchvision==0.15.2
14+
15+
# Jupyter extensions and tools
16+
jupyterlab==4.0.5
17+
jupyter-widgets==8.0.7
18+
ipywidgets==8.0.7
19+
jupyterlab-git==0.42.0
20+
21+
# Data processing and utilities
22+
requests==2.31.0
23+
beautifulsoup4==4.12.2
24+
openpyxl==3.1.2
25+
xlrd==2.0.1
26+
27+
# Visualization and interactive tools
28+
bokeh==3.2.2
29+
altair==5.0.1
30+
31+
# Development tools
32+
black==23.7.0
33+
flake8==6.0.0
34+
pytest==7.4.0

0 commit comments

Comments
 (0)