Docker: how to route path to port?

Advertisements

I am running 2 applications using separate Docker containers on the same server.
The first application uses the port 8000. Dockerfile:

EXPOSE 8000

docker-compose.yml:

command: uvicorn app.main:app --host 0.0.0.0 --port 8000
ports:
  - "8000:8000"

The second application uses the port 8001. Dockerfile:

EXPOSE 8001

docker-compose.yml:

command: uvicorn app.main:app --host 0.0.0.0 --port 8001
ports:
  - "8001:8001"

I have created DNS type A record:

api.mydomain.com to 123.123.123.123

api.mydomain.com:8000 and api.mydomain.com:8001 are both functioning. I want to route url path to port. For example:

api.mydomain.com/appone/ to api.mydomain.com:8000
api.mydomain.com/apptwo/ to api.mydomain.com:8001

Is it possible to do this using Docker? If yes, how can I do it?

>Solution :

Is it possible to do this using Docker?

Directly no, indirectly yes. Docker runs applications.

how can I do it?

You can run a proxy HTTP server that forwards domains to specific ports. Nginx and Apache are the most popular HTTP servers. There is also Fabio proxy.

You can run that server inside docker.

Leave a ReplyCancel reply