Created
December 9, 2025 18:26
-
-
Save chaws/64e685a13cef0a44414b32d5a781b935 to your computer and use it in GitHub Desktop.
Running tmate within docker (bump up security)
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
| FROM ubuntu:24.04 | |
| # Avoid prompts from apt | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install tmate and essential tools (add yours here) | |
| RUN apt-get update && apt-get install -y \ | |
| tmate \ | |
| python3 \ | |
| python3-ipython \ | |
| python3-venv \ | |
| python3-pip \ | |
| vim \ | |
| git \ | |
| curl \ | |
| wget \ | |
| jq \ | |
| sudo \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create user with same UID/GID as host user | |
| ARG USER_ID=1000 | |
| ARG GROUP_ID=1000 | |
| ARG USERNAME=developer | |
| # Ubuntu 24.04 comes with "ubuntu" user by default, we need to delete it | |
| RUN userdel -r ubuntu && \ | |
| groupadd -g ${GROUP_ID} ${USERNAME} && \ | |
| useradd -u ${USER_ID} -g ${GROUP_ID} -m -s /bin/bash ${USERNAME} && \ | |
| echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \ | |
| mkdir -p /home/${USERNAME}/.vim/swapfiles && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.vim | |
| # Switch to the user | |
| USER ${USERNAME} | |
| # Set working directory | |
| WORKDIR /home/${USERNAME}/workspace | |
| CMD ["tmate"] |
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
| #!/bin/bash | |
| set -xe | |
| USERNAME=$(whoami) | |
| # Image name | |
| IMAGE_NAME="tmate-secure" | |
| WORKSPACE_DIR="${PWD}" | |
| echo "Starting tmate session in Docker container..." | |
| echo "Your files will be in ~/workspace inside the container" | |
| echo "" | |
| # Run the container | |
| docker run -it --rm \ | |
| -v "${HOME}/.vimrc:/home/${USERNAME}/.vimrc:ro" \ | |
| -v "${HOME}/.bashrc:/home/${USERNAME}/.bashrc:ro" \ | |
| -v "${WORKSPACE_DIR}:/home/${USERNAME}/workspace" \ | |
| ${IMAGE_NAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment