基于Docker Compose配置Realm Object Server数据适配器遇HTTPS连接问题
Let's walk through fixing this HTTPS connection issue between your Data Adapter and Realm Object Server (ROS) in your Docker Compose setup—this is a common gotcha when working with containerized Realm services.
Confirm ROS is configured for HTTPS and ports are exposed correctly
First, ROS needs to have HTTPS enabled. You can either use self-signed certificates (auto-generated by ROS if you don't provide your own) or mount custom certificates. Update yourdocker-compose.ymlfor the ROS service to ensure:- The HTTPS port (default 9080) is exposed
- Environment variables enable HTTPS (and point to certs if using custom ones)
Example ROS service config:
services: ros: image: realm/realm-object-server:latest ports: - "9080:9080" # HTTPS port - "9081:9081" # Optional HTTP admin port environment: - REALM_SERVER_HTTPS_ENABLED=true # Uncomment below if using custom certs # - REALM_SERVER_HTTPS_CERT_PATH=/certs/cert.pem # - REALM_SERVER_HTTPS_KEY_PATH=/certs/key.pem volumes: # Mount custom certs directory if needed # - ./local-certs:/certsFix the Data Adapter's ROS connection URL
The error you're seeing means your adapter is trying to connect without specifying thehttps://protocol, or using an invalid URL format. Make sure the adapter's configuration uses a full HTTPS URL pointing to the ROS service name (Docker Compose lets services communicate via their service names).- In your adapter code, set the server URL explicitly:
const realm = require('realm'); const dataAdapter = new realm.DataAdapter({ serverUrl: 'https://ros:9080', // Critical: include https:// prefix // Other adapter config (auth, etc.) }); - Or pass the URL via an environment variable in your
docker-compose.ymlfor the adapter service:services: ros-adapter: build: ./your-adapter-directory environment: - ROS_SERVER_URL=https://ros:9080 depends_on: - ros
- In your adapter code, set the server URL explicitly:
Handle self-signed certificate trust (for development)
If ROS is using a self-signed certificate (the default), Node.js (which your Data Adapter runs on) will reject the connection by default. You have two options here:- Trust the ROS certificate (recommended for development, required for production):
- Copy the ROS-generated certificate to your adapter container and set the
NODE_EXTRA_CA_CERTSenvironment variable to point to it. Update your adapter's compose config:ros-adapter: # ... other config volumes: - ./ros-certs/ros-cert.pem:/usr/src/app/ros-cert.pem environment: - ROS_SERVER_URL=https://ros:9080 - NODE_EXTRA_CA_CERTS=/usr/src/app/ros-cert.pem
docker cp ros_1:/var/lib/realm/certs ./ros-certs - Copy the ROS-generated certificate to your adapter container and set the
- Temporarily disable certificate validation (only for local development, never use in production):
Add this line at the very top of your adapter's entry file:process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
- Trust the ROS certificate (recommended for development, required for production):
Verify Docker network connectivity
Ensure both ROS and the Data Adapter are on the same Docker network (Docker Compose creates a default network for all services in the file, so this should be true unless you've customized networks). To confirm, run:docker exec -it ros-adapter_1 ping rosIf the ping fails, explicitly define a network in your
docker-compose.ymland attach both services to it:networks: ros-internal: driver: bridge services: ros: # ... other config networks: - ros-internal ros-adapter: # ... other config networks: - ros-internalCheck ROS logs to confirm HTTPS is running
Finally, make sure ROS actually started the HTTPS server. Check the ROS container logs with:docker logs ros_1Look for a line like
HTTPS server listening on port 9080to confirm HTTPS is active.
内容的提问来源于stack exchange,提问作者Artur Miranda

