Skip to content

Commit

Permalink
fix: Update Dockerfile to address security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wktls63 committed Oct 4, 2024
1 parent 31d89c0 commit 1816b7b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
*.pyc
__pycache__/
.git/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pycache/
*.pid
*.bak
*.swp
.dockerignore

# 기타
.idea/
Expand Down
23 changes: 23 additions & 0 deletions services/user-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ignore environment and sensitive files
.env
*.env

# Ignore Python virtual environments
venv/
__pycache__/
*.pyc

# Ignore git and other VCS directories
.git/
.gitignore

# Ignore Docker-related files
Dockerfile
docker-compose.yml

# Ignore IDE files
*.idea/
*.vscode/

# Ignore node modules
node_modules/
15 changes: 12 additions & 3 deletions services/user-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Base image
FROM python:3.10

# Create a non-root user and set permissions
RUN useradd -m appuser

# Set the working directory
WORKDIR /app

# Copy requirements.txt and install dependencies
# Change ownership of the working directory to the non-root user
RUN chown -R appuser /app

# Copy only requirements.txt and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .
# Copy only the necessary application code
COPY app/ ./app

# Expose the port for user-service (8001)
EXPOSE 8001

# Switch to the non-root user
USER appuser

# Run the app using uvicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"]

0 comments on commit 1816b7b

Please sign in to comment.