OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I access FastAPI URL from my docker application?

  • Thread starter Thread starter Alexander Obidiegwu
  • Start date Start date
A

Alexander Obidiegwu

Guest
I have a front end react application hosted on a subdomain (www.admin.example.com). I also have a backend application that uses FastAPI to communicate with the front-end react application. This backend application is deployed using docker. The front end is built using npm run build command and deployed manually i.e build files are copied to the subdomain's root directory.

I am however having issues accessing this FastAPI backend application which is hosted using docker. I have tried using the IP address of my server + the port (https://server_ip_address:8000) but I do not get the response set on the / path from my FastAPI backend. That url (https://server_ip_address:8000), in fact, doesn't load a page. I get the error: This site can’t be reached.

But when I access https://server_ip_address I get a page loaded talking about nginx. I checked the docker logs and there's no error or response from the FastAPI application. I was told docker has it's own IP address too but I tried that and it doesn't work. I also can't access a URL such as https://server_ip_address:8000 from my front-end application else I get a CORS policy error. The overall question is, how do I access my FastAPI application listening on docker?

Docker Compose File:

Code:
services:
  db:
    build: .
    ports:
      - "8000:8000"
    secrets:
      - MONGODB_URI
      - LOGIN_SECRET_KEY

secrets:
  LOGIN_SECRET_KEY:
    file: admin_login_secret_key.txt
  MONGODB_URI:
    file: mongo_db_uri.txt

Docker File:

Code:
FROM python:3.12

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["fastapi", "run", "db.py", "--port", "8000"]

I wanted to know if the domain IP address and server IP address are different. I asked and someone from the team gave me the same IP address. So I want to they are the same.

NOTE

We have different subdomains on the domain www.example.com and I do not know if it's still possible to separately deploy a FastAPI application using docker without having conflicts. But this would depend on how I need to access it.
<p>I have a front end react application hosted on a subdomain (<a href="http://www.admin.example.com" rel="nofollow noreferrer">www.admin.example.com</a>). I also have a backend application that uses FastAPI to communicate with the front-end react application. This backend application is deployed using docker. The front end is built using <code>npm run build</code> command and deployed manually i.e build files are copied to the subdomain's root directory.</p>
<p>I am however having issues accessing this FastAPI backend application which is hosted using docker. I have tried using the IP address of my server + the port (<code>https://server_ip_address:8000</code>) but I do not get the response set on the <code>/</code> path from my FastAPI backend. That url (https://server_ip_address:8000), in fact, doesn't load a page. I get the error: <code>This site can’t be reached</code>.</p>
<p>But when I access <code>https://server_ip_address</code> I get a page loaded talking about nginx. I checked the docker logs and there's no error or response from the FastAPI application. I was told docker has it's own IP address too but I tried that and it doesn't work. I also can't access a URL such as <code>https://server_ip_address:8000</code> from my front-end application else I get a CORS policy error. The overall question is, how do I access my FastAPI application listening on docker?</p>
<p>Docker Compose File:</p>
<pre><code>services:
db:
build: .
ports:
- "8000:8000"
secrets:
- MONGODB_URI
- LOGIN_SECRET_KEY

secrets:
LOGIN_SECRET_KEY:
file: admin_login_secret_key.txt
MONGODB_URI:
file: mongo_db_uri.txt
</code></pre>
<p>Docker File:</p>
<pre><code>FROM python:3.12

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["fastapi", "run", "db.py", "--port", "8000"]
</code></pre>
<p><em>I wanted to know if the domain IP address and server IP address are different. I asked and someone from the team gave me the same IP address. So I want to they are the same.</em></p>
<p><strong>NOTE</strong></p>
<p>We have different subdomains on the domain <code>www.example.com</code> and I do not know if it's still possible to separately deploy a FastAPI application using docker without having conflicts. But this would depend on how I need to access it.</p>
 

Latest posts

Top