Docker Networking
Network Architecture
Section titled “Network Architecture”In the development environment, Pyxis CMS uses a bridge network. Containers communicate with each other using the service names defined in the docker-compose.yml file, avoiding issues with dynamic IP addresses.
Key Services
- pyxis-admin: Backend (Laravel) - internally accessible on port 8000.
- pyxis-view: Frontend - internally accessible on port 3000.
Communication: SSR vs. Client-side
Section titled “Communication: SSR vs. Client-side”This is the most critical concept in a Headless system. The API URL depends on where the request is sent from.
1. Server-Side Rendering (SSR)
Section titled “1. Server-Side Rendering (SSR)”When Astro (or other frontend) generates a page on the server side (inside the container), it must communicate directly with the backend container via the internal network.
- URL:
http://pyxis-admin:8000 - Why? The frontend container cannot see ports exposed on your machine’s localhost. To the container, localhost refers to itself.
2. Client-side (Browser)
Section titled “2. Client-side (Browser)”When the user’s browser sends a request (e.g., via JavaScript), it uses the address accessible from your operating system.
- URL:
http://localhost:8000
Environment Variables Setup
Section titled “Environment Variables Setup”In the frontend .env files, we separate these two worlds to ensure correct fetching:
# Internal communication URL (SSR)INTERNAL_API_URL=http://pyxis-admin:8000
# External communication URL (Browser)PUBLIC_API_URL=http://localhost:8000⚠️ CAUTION: Attempting to use localhost or 127.0.0.1 inside a container to fetch data from the API will result in a connection error. Always use the service name pyxis-admin.