fix(docker): correct port mapping and improve container startup
Some checks failed
Build and Push Docker Image (Gitea) / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image (Gitea) / build-and-push (push) Has been cancelled
- Fix port mapping from 5001:5001 to 5001:5000 to match internal application port - Add entrypoint script for proper database initialization and seeding - Set PORT environment variable to 5000 for consistency - Update Dockerfile to use entrypoint script with proper line ending handling
This commit is contained in:
@@ -17,8 +17,12 @@ COPY . .
|
|||||||
# Create data directory
|
# Create data directory
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
# Expose port
|
# Fix line endings for entrypoint script (in case of Windows checkout) and make executable
|
||||||
EXPOSE 5001
|
RUN sed -i 's/\r$//' entrypoint.sh && \
|
||||||
|
chmod +x entrypoint.sh
|
||||||
|
|
||||||
# Run commands to init db, seed data, and start server
|
# Expose port (default 5000)
|
||||||
CMD ["sh", "-c", "flask init-db && flask seed-db && gunicorn -w 4 -b 0.0.0.0:5001 app:app"]
|
EXPOSE 5000
|
||||||
|
|
||||||
|
# Use entrypoint script to init db, seed data, and start server
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
|||||||
18
calorie_tracker_app/entrypoint.sh
Normal file
18
calorie_tracker_app/entrypoint.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Initialize database
|
||||||
|
echo "Initializing database..."
|
||||||
|
flask init-db
|
||||||
|
|
||||||
|
# Seed database
|
||||||
|
echo "Seeding database..."
|
||||||
|
flask seed-db
|
||||||
|
|
||||||
|
# Start Gunicorn
|
||||||
|
# Use PORT environment variable if set, otherwise default to 5000
|
||||||
|
PORT=${PORT:-5000}
|
||||||
|
echo "Starting Gunicorn on port $PORT..."
|
||||||
|
exec gunicorn -w 4 -b 0.0.0.0:$PORT app:app
|
||||||
@@ -2,17 +2,19 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
calorie-tracker:
|
calorie-tracker:
|
||||||
|
build: ./calorie_tracker_app
|
||||||
image: git.jpaleviado.site/kingjaypee12/calorie-tracker:latest
|
image: git.jpaleviado.site/kingjaypee12/calorie-tracker:latest
|
||||||
container_name: calorie-tracker
|
container_name: calorie-tracker
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "5001:5001"
|
- "5001:5000"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=sqlite:////app/data/calorie_tracker.db
|
- DATABASE_URL=sqlite:////app/data/calorie_tracker.db
|
||||||
- SECRET_KEY=change-this-secret-key-in-production
|
- SECRET_KEY=change-this-secret-key-in-production
|
||||||
- API_NINJAS_KEY=${API_NINJAS_KEY}
|
- API_NINJAS_KEY=${API_NINJAS_KEY}
|
||||||
|
- PORT=5000
|
||||||
networks:
|
networks:
|
||||||
- casaos-net
|
- casaos-net
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user