Currently I'm trying to setup a simple web service. For this I'm using the phyton3 http.server class. The whole thing runs in a Docker container (called simple_webservice; exposing port 8010).
When running the container without traefik I'm able to access the website by calling http://localhost:8010.
The code I used for implementing my webserver can be found here:
import http.server
import socketserver
PORT = 8010
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
The docker-file is also simple (proxy is used for downloading via apt-get):
FROM ubuntu:latest
ENV http_proxy 'http://proxy:port'
ENV https_proxy 'http://proxy:port'
ENV no_proxy 'company.net'
RUN apt-get update && apt-get install -y \
build-essential \
python3
RUN mkdir /www
COPY ext/ /www
ADD ./entrypoint.sh /entrypoint.sh
ADD server.py /www/server.py
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "./entrypoint.sh"]
Here is my docker-compose.yml file for using my container with the traefik reverse proxy:
version: '3'
services:
simple_webservice:
build: .
image: "simple_webservice"
expose:
- 8010
networks:
- internal_network
- default
labels:
- traefik.passHostHeader=true
- traefik.docker.network=internal_network
- traefik.enable=true
- traefik.backend=simple_webservice
- traefik.frontend.rule=PathPrefix:/webservice
- traefik.port=8010
networks:
internal_network:
external: true
Now when accessing the very same web service by calling http://localhost/webservice it always returns:
Error response
Error code: 404
Message: File not found.
Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI
So I assume my service is still reachable and traefik behaves correctly but my webserver can't handle the Path Prefix /webservice? How can I fix this?
Edit: Answered by posting a workaround.
simple_webservice. - ndcltwebservice, relative to the Python file that runs the web server. - bellackncd /www && python3 server.py- agentsmith