I've been trying to dockerize an angular application with python backend following this. I did all but for the docker-compose file, it says that my app.py is not present in the folder.
my python app is in 'C:\Users\Fra\Desktop\Fra\uni\Tesi\Progetto\backend'
and my angular app is in 'C:\Users\Fra\Desktop\Fra\uni\Tesi\Progetto\frontend'
i'm leaving you the dockerfiles, that should help
('Dockerfile' placed in the backend folder)
FROM python:3.7-slim
COPY ./ /Users/Fra/Desktop/Fra/uni/Tesi/Progetto/backend/
WORKDIR /Users/Fra/Desktop/Fra/uni/Tesi/Progetto
ENV PYTHONUNBUFFERED 1
RUN pip freeze > /requirements.txt
CMD ["python","app.py"]
('Dockerfile' placed in the frontend folder)
FROM nginx:1.17.1-alpine
COPY /dist/macroPlan /usr/share/nginx/html
('docker-compose' placed in the /Progetto/ folder)
version: "3.3"
services:
app-backend:
build: ./backend/
image: app_backend
container_name: backend
restart: always
ports:
- 8082:8082
app-frontend:
build: ./frontend/
image: macroplan
container_name: frontend
restart: always
ports:
- 4200:4200
expose:
- "4200"
It's my first time doing something like this, what am i missing?
CodePudding user response:
Your WORKDIR
is /Users/Fra/Desktop/Fra/uni/Tesi/Progetto
but your app.py
file - which is required for container startup in CMD
- is located in /Users/Fra/Desktop/Fra/uni/Tesi/Progetto/backend/
folder.
Rewrite your backend Dockerfile to:
FROM python:3.7-slim
COPY ./ /Users/Fra/Desktop/Fra/uni/Tesi/Progetto/backend/
WORKDIR /Users/Fra/Desktop/Fra/uni/Tesi/Progetto/backend/
ENV PYTHONUNBUFFERED 1
RUN pip freeze > /requirements.txt
CMD ["python","app.py"]
Or if you want to have different workdir for some reason, you have to specify correct path for your app.py
file:
FROM python:3.7-slim
COPY ./ /Users/Fra/Desktop/Fra/uni/Tesi/Progetto/backend/
WORKDIR /Users/Fra/Desktop/Fra/uni/Tesi/Progetto
ENV PYTHONUNBUFFERED 1
RUN pip freeze > /requirements.txt
CMD ["python","./backend/app.py"]