Last active
January 16, 2025 22:08
-
-
Save marhensa/f1d2c9cc8f938e307eba842a7ba748cf to your computer and use it in GitHub Desktop.
full-guide-wsl-docker-segment-geospatial-gpu-pixienv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### WSL2 DEBIAN SETUP ##### | |
# wsl --install Debian | |
# wsluser | |
# password | |
echo cd ~ >> ~/.bashrc && source ~/.bashrc | |
sudo nano /etc/wsl.conf | |
```wsl.conf | |
[boot] | |
systemd=true | |
[automount] | |
enabled=false | |
[interop] | |
appendWindowsPath=false | |
[user] | |
default=wsluser | |
``` | |
exit | |
# wsl --terminate Debian | |
# wsl --shutdown | |
# wsl --export Debian E:\WSL\_Backup\Debian-InitialStart.tar | |
# wsl --unregister Debian | |
# wsl --import wslname E:\WSL\wslname\ E:\WSL\_Backup\Debian-InitialStart.tar | |
# wsl -d wslname | |
mkdir -p ~/dockerstuff | |
sudo nano /etc/fstab | |
```fstab | |
E:\\WSL\\_dockerstuff /home/wsluser/dockerstuff drvfs rw,uid=1000,gid=1000,metadata 0 0 | |
``` | |
exit | |
# wsl --terminate wslname | |
# wsl -d wslname | |
cd ~/dockerstuff | |
mkdir vol | |
mkdir compose | |
mkdir images | |
mkdir build | |
cd ~ | |
# install necessary packages for Debian WSL | |
sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get install -y wget curl unzip zstd pigz gpg git iptables uidmap dbus-user-session | |
exit | |
# wsl --terminate wslname | |
# wsl -d wslname | |
systemctl --user | |
# Ctrl+C (Close) | |
############################## | |
##### DOCKER ROOTLESS INSTALLATION ##### | |
curl -fsSL https://get.docker.com/rootless | sh | |
sudo loginctl enable-linger wsluser | |
echo -e '\nexport PATH=/home/wsluser/bin:$PATH\nexport DOCKER_HOST=unix:///run/user/1000//docker.sock' >> ~/.bashrc && source ~/.bashrc | |
mkdir -p ~/.docker/cli-plugins/ | |
LATEST_RELEASE=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') | |
curl -SL "https://github.com/docker/compose/releases/download/${LATEST_RELEASE}/docker-compose-linux-x86_64" -o ~/.docker/cli-plugins/docker-compose | |
chmod +x ~/.docker/cli-plugins/docker-compose | |
# if needed to map lower number ports | |
sudo setcap cap_net_bind_service=ep $HOME/bin/rootlesskit | |
docker --version | |
docker compose version | |
######################################## | |
##### NVIDIA DOCKER CONTAINER TOOLKIT ##### | |
## necessary for container to harnessing gpu capabilities of the host ## | |
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ | |
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ | |
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ | |
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list | |
sudo apt-get update | |
sudo apt-get install -y nvidia-container-toolkit | |
sudo nvidia-ctk config --set nvidia-container-cli.no-cgroups --in-place | |
nvidia-ctk runtime configure --runtime=docker --config=$HOME/.config/docker/daemon.json | |
systemctl --user restart docker | |
########################################### | |
##### CREATING DOCKERFILE FOR SEGMENT-GEOSPATIAL ##### | |
cd ~/dockerstuff | |
cd build | |
mkdir samgeo | |
cd samgeo | |
nano Dockerfile | |
```Dockerfile | |
# change to another nvidia cuda image base if needed | |
# https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags | |
FROM nvcr.io/nvidia/cuda:12.6.3-base-ubuntu24.04 | |
# Install system dependencies | |
RUN apt-get update -y && apt-get upgrade -y && \ | |
apt-get install -y --reinstall nano wget curl gpg git libgl1 libglib2.0-0 libsm6 libxext6 libxrender-dev sqlite3 && \ | |
apt-get autoclean && apt-get clean && rm -rf /var/lib/apt/lists/* | |
# Install pixi using the standalone installer | |
RUN curl -fsSL https://pixi.sh/install.sh | bash | |
# Ensure pixi is added to PATH | |
ENV PATH="/root/.pixi/bin:$PATH" | |
# Setup workspace and examples | |
WORKDIR /root | |
RUN git clone https://github.com/opengeos/segment-geospatial.git && \ | |
mkdir workspace && \ | |
mv /root/segment-geospatial/docs/examples /root/workspace/examples && \ | |
rm -fr /root/segment-geospatial | |
# Setup pixi environment with python 3.12.7 | |
WORKDIR /root/workspace | |
RUN pixi init && pixi add "python=3.12.7" | |
# Pin to python 3.12.7 | |
RUN printf '[tool.pixi]\nrequires-python = "==3.12.7"\n\n' > pyproject.toml | |
# Configure additional PyPI index URL for PyTorch | |
RUN printf '[pypi-options]\nextra-index-urls = ["https://download.pytorch.org/whl/cu124"]' >> pyproject.toml | |
# Add GDAL to pixi env | |
RUN pixi add gdal | |
# Add SQLite | |
RUN pixi add sqlite | |
# Add pip dependencies for installation in pixi env | |
RUN pixi add --pypi torch torchvision && \ | |
pixi add --pypi groundingdino-py segment-anything-fast jupyter jupyter-server-proxy && \ | |
pixi add --pypi segment-geospatial | |
# Cleaning up caches | |
RUN pixi clean cache -y && \ | |
find /root/.cache -mindepth 1 -delete | |
# Set environment variables | |
ARG LOCALTILESERVER_CLIENT_PREFIX='proxy/{port}' | |
ENV LOCALTILESERVER_CLIENT_PREFIX=$LOCALTILESERVER_CLIENT_PREFIX | |
# Activate jupyter extension and its jupyter server proxy config | |
WORKDIR /root/workspace | |
RUN pixi run jupyter server extension enable --sys-prefix jupyter_server_proxy | |
# Uncomment two lines below to immediately activate pixi env and running jupyter lab at port 8888 | |
# EXPOSE 8888 | |
# CMD ["pixi", "run", "jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"] | |
``` | |
###################################################### | |
##### CREATING IMAGE FROM DOCKERFILE ##### | |
# docker pull nvcr.io/nvidia/cuda:12.6.2-base-ubuntu24.04 | |
docker build -t segment-geospatial-cuda12 . | |
########################################## | |
##### EXPORT THE IMAGE TO TAR BACKUP ##### | |
docker save segment-geospatial-cuda12 | gzip > ~/dockerstuff/images/seggeo-cuda12.tar.gz | |
########################################## | |
##### REMOVE THE IMAGE ##### | |
docker rmi segment-geospatial-cuda12 | |
############################ | |
##### IMPORT IMAGE FROM TAR BACKUP ##### | |
docker load -i ~/dockerstuff/images/seggeo-cuda12.tar.gz | |
docker images | |
# if the name of docker image is different | |
# docker tag xxx segment-geospatial-cuda1262-cudnn-rt-ubuntu2404:latest | |
######################################## | |
##### RUNNING SEGMENT-GEOSPATIAL CONTAINER ##### | |
## setup the folders ## | |
# cd ~ | |
# mkdir dockerstuf | |
cd ~/dockerstuff | |
cd vol | |
mkdir samgeo | |
cd samgeo | |
mkdir data | |
mkdir cache | |
mkdir notebooks | |
mkdir jupyter | |
chown -R $USER:$USER ~/dockerstuff/vol/samgeo/cache ~/dockerstuff/vol/samgeo/data ~/dockerstuff/vol/samgeo/notebooks | |
chmod -R 775 ~/dockerstuff/vol/samgeo/cache ~/dockerstuff/vol/samgeo/data ~/dockerstuff/vol/samgeo/notebooks | |
cd ~/dockerstuff/vol/samgeo | |
## to run the container ## | |
docker run -it --name segment-geospatial-cuda12 --gpus all \ | |
-v ~/dockerstuff/vol/samgeo/jupyter:/root/.jupyter \ | |
-v ~/dockerstuff/vol/samgeo/cache:/root/.cache \ | |
-v ~/dockerstuff/vol/samgeo/data:/root/workspace/data \ | |
-v ~/dockerstuff/vol/samgeo/notebooks:/root/workspace/notebooks \ | |
-p 8888:8888 \ | |
--restart unless-stopped \ | |
segment-geospatial-cuda12 \ | |
/bin/bash | |
## then from bash terminal inside container use: | |
pixi run jupyter lab password | |
# (create password, hashed key will be stored in ~/dockerstuff/vol/samgeo/jupyter) | |
pixi run jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root | |
http://127.0.0.1:8888/lab | |
# (press Ctrl+D to exit) | |
## to start it again: | |
docker start segment-geospatial-cuda12 && docker exec -it segment-geospatial-cuda12 bash | |
pixi run jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root | |
http://127.0.0.1:8888/lab | |
# (press Ctrl+D to exit) | |
## to use bash only and activate pixi environment for running python and others: | |
docker start segment-geospatial-cuda12 && docker exec -it segment-geospatial-cuda12 bash | |
pixi shell | |
# (run your python command etc) | |
# (press Ctrl+D to exit, twice) | |
## to stop the container: | |
docker stop segment-geospatial-cuda12 | |
################################################ | |
##### TESTING CONTAINER FOR BASH OPTION ##### | |
# pixi shell | |
python | |
``` | |
import torch | |
torch.cuda.is_available() | |
torch.cuda.get_device_name(0) | |
import leafmap | |
from samgeo import SamGeo2, regularize | |
``` | |
############################################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment