Standalone API image
Closed this issue · 10 comments
Hi, I am trying to use a standalone API image as I am trying to deploye xBrowserSync behind an existing nginx installation.
I have a container running MongoDB listening on the host's interface at the default port (27017
). I can confirm this running as I can connect to this MongoDB instance from a different physical host on my local network.
Unfortunately, the standalone xBrowserSync image (xbrowsersync
/api
:latest
) seems to crash repeatedly. I have followed instructions from https://github.com/xbrowsersync/api-docker#running-the-api-image and using some of the options from https://github.com/xbrowsersync/api#4-modify-configuration-settings.
I can't seem to get to view the logs, and I cannot login to the container, as it crashes repeatedly.
Please could you help me with how I can debug it?
(It doesn't help that I am fairly new to both Docker and MongoDB).
If you are already running MongoDB then it's likely conflicting with the MongoDB container in the docker-compose file, likely a port conflict. Stop all existing containers and then try again.
If you are already running MongoDB then it's likely conflicting with the MongoDB container in the docker-compose file, likely a port conflict. Stop all existing containers and then try again.
@nero120 , thanks for your response. I am not running the API from the docker-compose file. I am running a container directly from the API image; so I presume that a second instance is not running.
Ok what do you see if you run:
docker logs [api_container_name]
(replace [api_container_name]
with the name of the xBrowserSync API container )
@nero120 , unfortunately I was unable to re-trace my steps to get the Mongo instance setup and subsequently with the xBrowserSync API image. I have given up on reusing an existing Mongo instance and used the composer file. I removed the traefik section of the docker-compose file, but had to move the ports declarations from traefik to api sections.
Ok thanks for the update @viharm, glad that you're up and running now in any case.
I ended up using the exclusive MongoDB image configured for use with the API image. However I wanted to control the public-facing side, so put it behind an nginx instance.
Here's my docker compose file to use without traefik
version: "3.7"
volumes:
xbs-db-data:
services:
db:
container_name: "xbs-db"
environment:
- "MONGO_INITDB_DATABASE=xbrowsersync"
- "MONGO_INITDB_ROOT_PASSWORD=$XBS_DB_PASSWORD"
- "MONGO_INITDB_ROOT_USERNAME=$XBS_DB_USERNAME"
image: "mongo:4.2.0"
labels:
- "traefik.enable=false"
networks:
- "xbs-net"
restart: "always"
volumes:
- "xbs-db-data:/data/db"
- "./mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
api:
container_name: "xbs-api"
depends_on:
- "db"
environment:
- "XBROWSERSYNC_DB_PWD=$XBS_DB_PASSWORD"
- "XBROWSERSYNC_DB_USER=$XBS_DB_USERNAME"
image: "xbrowsersync/api:1.1.10"
labels:
- "traefik.frontend.rule=Host:$XBS_API_HOSTNAME"
- "traefik.port=8080"
networks:
- "xbs-net"
ports:
- "8080:8080"
restart: "always"
volumes:
- "./settings.json:/usr/src/api/config/settings.json"
networks:
xbs-net:
I have finally been able to run a standalone API image without an exclusive instance of MongoDB or Traefik. Although this issue has been closed, I thought I'd add some more descriptions.
Prerequisite
- Docker
- MongoDB
- Reverse proxy (depending on use case)
Installation and setup
Download
Clone from https://github.com/xbrowsersync/api-docker
Container setup
Here's my .env
file
XBS_API_HOSTNAME=xbs.domain.tld
XBS_DB_PASSWORD=dbpassword
XBS_DB_USERNAME=dbuser
Here's my settings.json
file
{
"db": {
"host": "mongodatabasehost.local",
"port": 27017,
"connTimeout": 30000,
"authSource": "authdb",
"name": "datadb",
"username": "dbuser",
"password": "dbpassword"
},
"dailyNewSyncsLimit": 8,
"maxSyncSize": 1048576,
"throttle": {
"maxRequests": 0
},
"status": {
"message": "This is my browser sync service."
}
}
Then create a Docker container with the following configuration (field names are based on Portainer, but can be easily translated to any Docker container management tool (including CLI).
Field | Value |
---|---|
Name | xbs |
Image | xbrowsersync/api:1.1.12 (use the appropriate tag) |
Pull image | 🗹 |
Volume map | host:/usr/local/src/xbrowsersync/settings.json -> container:/usr/src/api/config/settings.json |
Network | Host |
Environment | XBROWSERSYNC_DB_USER =dbuser XBROWSERSYNC_DB_PWD =dbpassword |
Labels | traefik.enable =false |
Restart policy | Always |
Here's my reverse proxy configuration from my existing Nginx installation, using a new subdomain to point to the API.
server {
server_name xbs.domain.tld;
listen 80;
if ($scheme = http) {
# Force redirection to HTTPS.
return 301 https://$host:443$request_uri;
}
listen 443 ssl;
ssl_certificate /path/to/xbs.crt.pem;
ssl_certificate_key /path/to/xbs.privkey.pkcs8.pem;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_log /var/log/nginx/xbs_error.log warn;
access_log /var/log/nginx/xbs_access.log combined;
server_tokens off;
}
Hope this helps someone who wants to use their existing database and reverse proxy.