Skip to content

Commit 21bf11e

Browse files
Run containers as non-root with host UID/GID mapping (#3127)
Co-authored-by: Tao Sun <168447269+fengju0213@users.noreply.github.com>
1 parent fe81cc2 commit 21bf11e

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

.container/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
FROM python:3.10-bookworm
22

33
RUN pip install uv
4+
RUN groupadd -r appuser && useradd -r -g appuser appuser
45

56
WORKDIR /app/camel
67
COPY . .
8+
RUN chown -R appuser:appuser /app/camel
79

810
RUN uv venv .venv --python=3.10 && \
911
. .venv/bin/activate && \
@@ -14,4 +16,6 @@ RUN uv venv .venv --python=3.10 && \
1416
ENV VIRTUAL_ENV=/app/camel/.venv
1517
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
1618

19+
USER appuser
20+
1721
CMD ["bash"]

.container/docker-compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ services:
99
- ../:/app/camel
1010
env_file:
1111
- .env
12+
user: "${UID:-1000}:${GID:-1000}"
1213
command: ["tail", "-f", "/dev/null"]
14+
15+
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
FROM python:3.10-bookworm
22

3-
# Install uv
43
RUN pip install uv
4+
RUN groupadd -r appuser && useradd -r -g appuser appuser
55

66
COPY . /app/camel
7-
87
WORKDIR /app/camel
8+
RUN chown -R appuser:appuser /app/camel
99

10-
# Setup virtual environment and install dependencies
1110
RUN uv venv .venv --python=3.10 && \
1211
. .venv/bin/activate && \
1312
uv pip install -e ".[all, dev, docs]" && \
1413
pip install pre-commit mypy
1514

16-
CMD ["tail", "-f", "/dev/null"]
15+
USER appuser
16+
17+
CMD ["tail", "-f", "/dev/null"]

camel/interpreters/docker/Dockerfile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# syntax=docker/dockerfile:1
2-
32
FROM ubuntu:22.04
43

5-
# Set environment variable to avoid interactive prompts
64
ENV DEBIAN_FRONTEND=noninteractive
75

8-
# Update and install base utilities
96
RUN apt-get update && apt-get install -y \
107
build-essential \
118
software-properties-common \
@@ -20,7 +17,6 @@ RUN apt-get update && apt-get install -y \
2017
&& apt-get clean \
2118
&& apt-get autoremove -y
2219

23-
# Install Python 3.10 and its dependencies
2420
RUN add-apt-repository ppa:deadsnakes/ppa && \
2521
apt-get update && \
2622
apt-get install -y \
@@ -34,32 +30,27 @@ RUN add-apt-repository ppa:deadsnakes/ppa && \
3430
&& apt-get clean \
3531
&& apt-get autoremove -y
3632

37-
# Install R
3833
RUN apt-get update && \
3934
apt-get install -y r-base && \
4035
rm -rf /var/lib/apt/lists/* && \
4136
apt-get clean && \
4237
apt-get autoremove -y
4338

44-
# Install NodeJS 22.x
4539
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
4640
apt-get install -y nodejs && \
4741
rm -rf /var/lib/apt/lists/* && \
4842
apt-get clean && \
4943
apt-get autoremove -y
5044

51-
# Install Poetry
5245
RUN curl -fsSL https://install.python-poetry.org | python3.10 - && \
5346
ln -s ~/.local/bin/poetry /usr/local/bin/poetry
5447

55-
# Upgrade pip and install base Python packages
5648
RUN python3.10 -m pip install --upgrade pip setuptools wheel
57-
58-
# Install uv using pip instead of the shell script
5949
RUN pip install uv
6050

61-
# Setup working directory
51+
RUN groupadd -r devuser && useradd -r -m -g devuser devuser
6252
WORKDIR /workspace
53+
RUN chown -R devuser:devuser /workspace
54+
USER devuser
6355

64-
# Set default shell
6556
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)