$ -weight: 500;">docker exec -it app netstat -tlnp
-weight: 500;">docker exec -it app netstat -tlnp
-weight: 500;">docker exec -it app netstat -tlnp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
# main.py
import uvicorn
from fastapi import FastAPI app = FastAPI() @app.get("/health")
def health(): return {"-weight: 500;">status": "healthy"} if __name__ == "__main__": # This will NOT work for inter-container communication # uvicorn.run(app, host="127.0.0.1", port=8000) # This binds to all interfaces uvicorn.run(app, host="0.0.0.0", port=8000)
# main.py
import uvicorn
from fastapi import FastAPI app = FastAPI() @app.get("/health")
def health(): return {"-weight: 500;">status": "healthy"} if __name__ == "__main__": # This will NOT work for inter-container communication # uvicorn.run(app, host="127.0.0.1", port=8000) # This binds to all interfaces uvicorn.run(app, host="0.0.0.0", port=8000)
# main.py
import uvicorn
from fastapi import FastAPI app = FastAPI() @app.get("/health")
def health(): return {"-weight: 500;">status": "healthy"} if __name__ == "__main__": # This will NOT work for inter-container communication # uvicorn.run(app, host="127.0.0.1", port=8000) # This binds to all interfaces uvicorn.run(app, host="0.0.0.0", port=8000)
# This works (DNS resolution)
nslookup app # This works (network layer)
ping app # This fails (application layer)
-weight: 500;">curl http://app:8000
# -weight: 500;">curl: (7) Failed to connect to app port 8000: Connection refused
# This works (DNS resolution)
nslookup app # This works (network layer)
ping app # This fails (application layer)
-weight: 500;">curl http://app:8000
# -weight: 500;">curl: (7) Failed to connect to app port 8000: Connection refused
# This works (DNS resolution)
nslookup app # This works (network layer)
ping app # This fails (application layer)
-weight: 500;">curl http://app:8000
# -weight: 500;">curl: (7) Failed to connect to app port 8000: Connection refused
-weight: 500;">docker exec -it app sh
netstat -tlnp | grep 8000
# tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
-weight: 500;">docker exec -it app sh
netstat -tlnp | grep 8000
# tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
-weight: 500;">docker exec -it app sh
netstat -tlnp | grep 8000
# tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1/python
netstat -tlnp | grep 8000
# tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
netstat -tlnp | grep 8000
# tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
netstat -tlnp | grep 8000
# tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1/python
services: app: build: . container_name: app networks: - mynetwork ports: - "8000:8000" # Host access only environment: - REDIS_HOST=redis - REDIS_PORT=6379 depends_on: - redis redis: image: redis:alpine container_name: redis networks: - mynetwork # No ports needed unless you want host access to Redis networks: mynetwork: driver: bridge
services: app: build: . container_name: app networks: - mynetwork ports: - "8000:8000" # Host access only environment: - REDIS_HOST=redis - REDIS_PORT=6379 depends_on: - redis redis: image: redis:alpine container_name: redis networks: - mynetwork # No ports needed unless you want host access to Redis networks: mynetwork: driver: bridge
services: app: build: . container_name: app networks: - mynetwork ports: - "8000:8000" # Host access only environment: - REDIS_HOST=redis - REDIS_PORT=6379 depends_on: - redis redis: image: redis:alpine container_name: redis networks: - mynetwork # No ports needed unless you want host access to Redis networks: mynetwork: driver: bridge
app: build: . command: uvicorn main:app --host 0.0.0.0 --port 8000
app: build: . command: uvicorn main:app --host 0.0.0.0 --port 8000
app: build: . command: uvicorn main:app --host 0.0.0.0 --port 8000 - DNS resolves app to something like 172.18.0.2
- TCP SYN packet travels to that IP on port 8000
- If the app is bound to 127.0.0.1:8000, the kernel checks: "Is there a socket listening on 172.18.0.2:8000?" Answer: no.
- Kernel replies with RST (connection refused) or drops the packet (timeout)