Skip to content

Instantly share code, notes, and snippets.

@alexlib
Forked from Moosems/Dockerfile
Created August 25, 2025 21:41
Show Gist options
  • Save alexlib/481623e77effef7d7be979f1f832e7cc to your computer and use it in GitHub Desktop.
Save alexlib/481623e77effef7d7be979f1f832e7cc to your computer and use it in GitHub Desktop.

Revisions

  1. @Moosems Moosems revised this gist May 23, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,9 @@ RUN sudo apt-get update && apt-get install -y \
    # Install the dependencies
    RUN pip install --upgrade pip; \
    pip3 install -r requirements.txt

    # Create /.local directory
    RUN mkdir /.local; mkdir /.local/share; chmod 777 /.local; chmod 777 /.local/share

    # Set the display port to avoid crash and to be able to use the container with a remote host
    ENV DISPLAY=:0
  2. @Moosems Moosems revised this gist May 23, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    # Get the path to the user data directory
    dir = Path(user_data_dir()) / "HelloWorld"

    # Create the directory if it doesn't exist
    dir.mkdir(parents=True, exist_ok=True)
    # Create the directory
    dir.mkdir(parents=True)

    root.mainloop()
  3. @Moosems Moosems revised this gist May 23, 2023. No changes.
  4. @Moosems Moosems created this gist May 23, 2023.
    39 changes: 39 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    FROM ubuntu:20.04 as builder

    FROM python:3.10.7

    # Create a user to run the application
    RUN apt-get update && \
    apt-get -y install sudo

    RUN useradd -ms /bin/bash docker && echo "docker:docker" | chpasswd && adduser docker sudo

    # Allow sudo without password (add docker user to sudoers)
    RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

    # Switch to the docker user
    USER docker

    # Become root
    USER root

    # Set the working directory for the container
    WORKDIR /home/docker
    COPY . .

    # Install PIL and tk dependencies
    RUN sudo apt-get install apt-utils
    RUN sudo apt-get update && apt-get install -y \
    python3-pil \
    python3-tk \
    python3-pil.imagetk

    # Install the dependencies
    RUN pip install --upgrade pip; \
    pip3 install -r requirements.txt

    # Set the display port to avoid crash and to be able to use the container with a remote host
    ENV DISPLAY=:0

    # Run the application
    CMD ["python3", "main.py"]
    14 changes: 14 additions & 0 deletions docker.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Build the image
    docker build -t dip .

    # # Get IP address of Mac
    IP=$(/usr/sbin/ipconfig getifaddr en0)

    # # Print IP address
    echo "IP: $IP"

    # # Allow connections through XQuartz
    /opt/X11/bin/xhost + "$IP"

    # Run the container
    docker run -u=$(id -u $USER):$(id -g $USER) -e DISPLAY=$IP:0 -v /tmp/.X11-unix:/tmp/.X11-unix:rw --rm -it dip
    16 changes: 16 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    from tkinter import Tk, Label
    from platformdirs import user_data_dir
    from pathlib import Path

    root = Tk()
    root.title("Hello World")
    root.geometry("400x200")
    Label(root, text="Hello World").pack()

    # Get the path to the user data directory
    dir = Path(user_data_dir()) / "HelloWorld"

    # Create the directory if it doesn't exist
    dir.mkdir(parents=True, exist_ok=True)

    root.mainloop()
    1 change: 1 addition & 0 deletions requirements.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    platformdirs