Skip to content

Instantly share code, notes, and snippets.

@boriel
Last active March 1, 2026 23:21
Show Gist options
  • Select an option

  • Save boriel/c5e9824624ad2e75f53f64f52b5f59fa to your computer and use it in GitHub Desktop.

Select an option

Save boriel/c5e9824624ad2e75f53f64f52b5f59fa to your computer and use it in GitHub Desktop.
Simple dockerfile to run opencode in a sandbox
FROM ubuntu:24.04
ARG UID=1000
ARG GID=1000
ARG USERNAME=dev
RUN apt update && apt dist-upgrade -y
RUN apt install -y \
adduser \
curl \
less \
vim
# Creates group if not exists
RUN if ! getent group ${GID} >/dev/null; then \
groupadd -g ${GID} ${USERNAME}; \
fi
# Creates user if not exits
RUN if ! getent passwd ${UID} >/dev/null; then \
useradd -m -u ${UID} -g ${GID} -s /bin/bash ${USERNAME}; \
fi
# If UID exist get real username
RUN REAL_USERNAME=$(getent passwd ${UID} | cut -d: -f1) && \
echo "Real user detected: ${REAL_USERNAME}" && \
echo "export PS1='[dev-container]\\u@\\h:\\w\\$ '" >> /home/${REAL_USERNAME}/.bashrc
USER ${UID}:${GID}
RUN curl -fsSL https://opencode.ai/install | bash
WORKDIR /app
CMD ["/bin/bash"]
@boriel
Copy link
Author

boriel commented Mar 1, 2026

This can be build with:

docker build . \
   --build-arg UID=$(id -u) \
   --build-arg GID=$(id -g) \
   -t opencode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment