ariansyahdedy commited on
Commit
2476522
·
1 Parent(s): c13745d

install on user

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -21
Dockerfile CHANGED
@@ -1,38 +1,39 @@
1
  FROM python:3.10
2
 
3
- # Install system dependencies
4
  RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0
5
 
6
- # Install Poetry
7
- RUN curl -sSL https://install.python-poetry.org | python3 -
8
 
9
- # Set Poetry path (ensures it's available in future RUN commands)
10
- ENV PATH="/root/.local/bin:$PATH"
11
 
12
- # Create a symlink so Poetry is accessible system-wide
13
- RUN ln -s /root/.local/bin/poetry /usr/local/bin/poetry
14
 
15
- ## (Optional) If you want to keep 'USER' for final container usage,
16
- # just do all installations as root FIRST, then switch user at the end.
17
- # But for a simpler approach in Docker, you can remain root entirely.
18
-
19
- FROM python:3.10
20
-
21
- # Install Poetry
22
- RUN curl -sSL https://install.python-poetry.org | python3 -
23
-
24
- # Set Poetry in PATH
25
- ENV PATH="/root/.local/bin:$PATH"
26
-
27
- # Make sure script is executable (usually it already is, but just to be safe):
28
- RUN chmod +x /root/.local/bin/poetry
29
 
 
30
  WORKDIR /code
31
 
 
32
  COPY pyproject.toml poetry.lock /code/
 
 
33
  RUN poetry install --no-root --no-interaction --no-ansi
34
 
 
35
  COPY . /code
36
 
 
 
 
 
 
 
 
37
  EXPOSE 7860
 
 
38
  CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.10
2
 
3
+ # Install system deps
4
  RUN apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0
5
 
6
+ # Set an env so Poetry installs into /usr/local
7
+ ENV POETRY_HOME="/usr/local/poetry"
8
 
9
+ RUN curl -sSL https://install.python-poetry.org | python3 - --yes
 
10
 
11
+ # Add Poetry to the PATH
12
+ ENV PATH="/usr/local/poetry/bin:$PATH"
13
 
14
+ # Create a non-root user
15
+ RUN useradd -m -u 1000 user
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ # Use /code as working directory
18
  WORKDIR /code
19
 
20
+ # Copy dependency files
21
  COPY pyproject.toml poetry.lock /code/
22
+
23
+ # Install dependencies as root first
24
  RUN poetry install --no-root --no-interaction --no-ansi
25
 
26
+ # Now copy the rest of the project
27
  COPY . /code
28
 
29
+ # (Optional) Adjust ownership
30
+ RUN chown -R user:user /code
31
+
32
+ # Switch to the non-root user
33
+ USER user
34
+
35
+ # Expose port
36
  EXPOSE 7860
37
+
38
+ # Run
39
  CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]