You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But sometimes people need to install uv and switch to a non-root user at runtime.
I could NOT get it to work. Here's a somewhat commented out example of what I tried but not everything. I tried installing uv to a non-root folder and giving the web user access to the cache, install directory, and virtual environment but I couldn't get ANYTHING to work. We're talking about two determined devs collaborating for multiple hours. Is there any way y'all could produce a version of the uv docker example that allows installation and package installation during the build but still allows another user to run the uv entrypoint? We can't be the only people trying to do this.
FROM python:3.12
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y apt-utils
RUN apt-get update && apt-get install -y --upgrade \
ca-certificates \
curl \
git \
nginx \
gettext \
locales \
supervisor \
vim
# Install supervisord confCOPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Setup nginxRUN rm /etc/nginx/sites-enabled/default
RUN ln -s /code/nginx.conf /etc/nginx/sites-enabled/tungsten.conf
# Localization / terminal UTF-8 handlingRUN locale-gen en_US.UTF-8
RUN update-locale en_US.UTF-8
ENV LANG=en_US.UTF-8
# Create and use web-userRUN groupadd web-user --gid 2001
RUN useradd --uid 2001 --gid 2001 -d /code web-user
# nginx and gunicorn setupCOPY . /code
# Download uv installerADD https://astral.sh/uv/install.sh /code/uv-installer.sh
RUN chown -R 2001:2001 /code
RUN chown -R 2001:2001 /var/lib/nginx
RUN chown -R 2001:2001 /var/log/nginx
RUN mkdir /logs
RUN chown 2001:2001 /logs
RUN mkdir /logs/nginx
RUN chown 2001:2001 /logs/nginx
RUN mkdir /logs/gunicorn
RUN chown 2001:2001 /logs/gunicorn
USER 2001:2001
# Configure Django project# Install uvRUN mkdir -p /code/uv-cache/uv
ENV UV_CACHE_DIR=/code/uv-cache
RUN sh /code/uv-installer.sh && rm /code/uv-installer.sh
ENV PATH="/root/.cargo/bin/:$PATH"
mkdir -p /code/uv-cache/uv
ENV PATH="/code/.cargo/uv/:$PATH"# Enable bytecode compilationENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking since it's a mounted volumeENV UV_LINK_MODE=copy
ENV DJANGO_PRODUCTION=true
ENV DJANGO_SETTINGS_MODULE=tungsten.settings
# Set workdirWORKDIR /code
ENV PATH="/code/.venv/bin:$PATH"# Install dependencies# we did try this with /code/RUN --mount=type=cache,target=/root/.cache/uv \
uv sync
# Place executables in the environment at the front of the pathRUN chmod ug+x /code/setup_cert.sh
RUN chmod ug+x /code/initialize.sh
## Create a registry of static filesRUN uv run /code/manage.py collectstatic --noinput
# Still using a local memory database for a few thingsRUN uv run /code/manage.py migrate --noinput
# Compile translation filesRUN uv run /code/manage.py compilemessages
# Expose ports# 80 = Nginx# 8000 = Gunicorn# 3306 = postgresEXPOSE 80 8000 3306
# Run Supervisor (i.e., start postgres, nginx, and gunicorn)ENTRYPOINT ["uv", "run", "/code/initialize.sh"]
The text was updated successfully, but these errors were encountered:
danieltalsky
changed the title
Add instructions to make a docker file that doesn't use root
Add instructions to make a docker file that doesn't use root at runtime
Dec 20, 2024
Thank you for pointing me in the right direction! Any chance you would consider adding a fully working example recommendation to your dockerfile example repo?
I really appreciate this example:
https://github.com/astral-sh/uv-docker-example/blob/main/Dockerfile
But sometimes people need to install uv and switch to a non-root user at runtime.
I could NOT get it to work. Here's a somewhat commented out example of what I tried but not everything. I tried installing uv to a non-root folder and giving the web user access to the cache, install directory, and virtual environment but I couldn't get ANYTHING to work. We're talking about two determined devs collaborating for multiple hours. Is there any way y'all could produce a version of the uv docker example that allows installation and package installation during the build but still allows another user to run the uv entrypoint? We can't be the only people trying to do this.
The text was updated successfully, but these errors were encountered: