Skip to content

Instantly share code, notes, and snippets.

@cloneofsimo
Last active May 1, 2024 09:16
Show Gist options
  • Save cloneofsimo/e4226f63443bf6386df846b06ff8d420 to your computer and use it in GitHub Desktop.
Save cloneofsimo/e4226f63443bf6386df846b06ff8d420 to your computer and use it in GitHub Desktop.
dockersetup.md

Setting up a Docker environment with PyTorch on your Linux server so that your friends can access it involves several steps, including installing Docker, pulling or building a PyTorch Docker image, and configuring Docker to ensure it is accessible securely from other machines. Here’s a step-by-step guide to get you started:

Step 1: Install Docker

  1. Update your system: Ensure your package lists and installed packages are updated.

    sudo apt update && sudo apt upgrade -y
  2. Install Docker: Install Docker using the convenience script from Docker which works on many Linux distributions.

    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
  3. Add your user to the Docker group (to run Docker as a non-root user):

    sudo usermod -aG docker $USER
    newgrp docker

Step 2: Get PyTorch Docker Image

You can either pull an official PyTorch image from Docker Hub or build your own.

  • Pull from Docker Hub:

    docker pull pytorch/pytorch:latest
  • Build your own Dockerfile: If you have specific dependencies, you might want to build your own image.

    • Create a Dockerfile:

      # Use an official PyTorch runtime as a parent image
      FROM pytorch/pytorch:latest
      
      # Optionally install additional dependencies
      RUN pip install matplotlib scipy
    • Build your Docker image:

      docker build -t my-pytorch-image .

Step 3: Run PyTorch Container

Run the container and map the ports if you need any applications to be accessible over the network.

docker run -it -p 8888:8888 --name my-torch-container my-pytorch-image

Here, -p 8888:8888 maps port 8888 on the host to port 8888 on the container, useful if you're running Jupyter notebooks.

Step 4: Configure Security and Access

  1. Configure the firewall: Ensure that only specific ports are exposed to the internet or to specific IP addresses for security.

    sudo ufw allow from <friend's IP> to any port 8888
    sudo ufw enable
  2. Set up a VPN or SSH Tunneling: For better security, consider setting up a VPN or using SSH tunneling for your friends to access your server:

    • SSH Tunneling:
      ssh -L 8888:localhost:8888 user@your-server-ip
    • VPN: Setting up a VPN server on your host allows secure access to your internal network.

Step 5: Maintenance and Updates

  • Update Docker images regularly to get the latest security updates and patches.
  • Monitor Docker containers using tools like Portainer or command-line tools to check logs, resource usage, etc.

Step 6: Documentation

  • Document the setup process, configurations, and usage instructions for your friends, so they can troubleshoot or understand the setup better.

With these steps, you should have a basic PyTorch Docker environment running on your Linux server that your friends can access. Always consider security implications and best practices when exposing your server to external access.


distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment