xbrowsersync / api-docker

xBrowserSync API for Docker
235 stars 56 forks source link

API Container keeps restarting #9

Closed The-Inamati closed 4 years ago

The-Inamati commented 4 years ago

Hi, I desperately need your help. I have tried to deploy xbrowsersync with docker compose for several times now and the api container keeps restarting.

I tried with image versions 1.10,1.11 and 1.12.

My docker-compose file is

 xbrowserdb:
    container_name: "xbrowserdb"
    environment:
      - "MONGO_INITDB_DATABASE=xbrowsersync"
      - "MONGO_INITDB_ROOT_PASSWORD=$XBROWSER_DB_PASSWORD"
      - "MONGO_INITDB_ROOT_USERNAME=$XBROWSER_DB_USERNAME"
    image: "mongo:4.2.0"
    networks:
      - "traefik"
    restart: "always"
    volumes:
      - "xbrowsersync:/data/db"
      - "$USERDIR/xbrowser/mongoconfig.js:/docker-entrypoint-initdb.d/mongoconfig.js"
  xbrowserapi:
    container_name: "xbrowserapi"
    depends_on:
      - "xbrowserdb"
    environment:
      - "XBROWSERSYNC_DB_PWD=$XBROWSER_DB_PASSWORD"
      - "XBROWSERSYNC_DB_USER=$XBROWSER_DB_USERNAME"
    image: "xbrowsersync/api:1.1.12"
    networks:
      - "traefik"
    ports:
      - "8180:8080"
    restart: "always"
    volumes:
      - "$USERDIR/xbrowser/settings.json:/usr/src/api/config/settings.json"
    labels:
      - "traefik.enable=true"
      ## HTTP Routers
      - "traefik.http.routers.xbrowser.entrypoints=https"
      - "traefik.http.routers.xbrowser.rule=Host(`$XBROWSER_SUBDOMAIN.$DOMAINNAME`)"
      - "traefik.http.routers.xbrowser.tls=true"
      ## Middlewares
      - "traefik.http.routers.xbrowser.middlewares=chain-no-auth@file" # No Authentication
      ## HTTP Services
      - "traefik.http.routers.xbrowser.service=xbrowser"
      - "traefik.http.services.xbrowser.loadbalancer.server.port=8180"

I also have tried with the default compose file in github just changing the network and it still restarts. All the variables are in the env file. I have over 40 containers and this is the only one with this behavior.

I also provided the settings.json and mongoconfig.js as needed.

I tried running the container with

docker run --name xbs-api -p 8180:8080 -e XBROWSERSYNC_DB_USER -e XBROWSERSYNC_DB_PWD -v $USERDIR/xbrowser/settings.json:/usr/src/api/config/settings.json -d xbrowsersync/api providing the variables and still restarts.

Bind mounts have 777 permissions just in case and nothing.

the mongoconfig.js file only has what's on github and the settings.json has

{
  "allowedOrigins": [],
  "dailyNewSyncsLimit": 0,
  "db": {
    "authSource": "admin",
    "connTimeout": 30000,
    "host": "xbrowserdb",
    "name": "xbrowsersync",
    "useSRV": false,
    "username": "",
    "password": "",
    "port": 27017
  },
  "location": "",
  "log": {
    "file": {
      "enabled": true,
      "level": "info",
      "path": "/var/log/xBrowserSync/api.log",
      "rotatedFilesToKeep": 5,
      "rotationPeriod": "1d"
    },
    "stdout": {
      "enabled": true,
      "level": "info"
    }
  },
  "maxSyncs": 5242,
  "maxSyncSize": 512000,
  "server": {
    "behindProxy": true,
    "host": "127.0.0.1",
    "https": {
      "certPath": "",
      "enabled": false,
      "keyPath": ""
    },
    "port": 8080,
    "relativePath": "/"
  },
  "status": {
    "allowNewSyncs": true,
    "message": "",
    "online": true
  },
  "tests": {
    "db": "xbrowsersynctest",
    "port": 8081
  },
  "throttle": {
    "maxRequests": 1000,
    "timeWindow": 300000
  }
}

The container restarts too fast to access and doesn't log anything. I tried bind mounting the log directory but nothing is written. I also ran the container with entrypoint /bin/ash to keep it from restarting and doesn't work and nothing gets logged.

What am I missing?

nero120 commented 4 years ago

Sounds like a docker issue to me, I've never encountered containers restarting like you describe - if something in the container doesn't work (e.g. the api doesn't start correctly) then the container will keep running but the api won't be accessible.

The-Inamati commented 4 years ago

When what's supposed to run in the container fails the container stops. But if you have restart always like I do it will keep stopping and starting ad eternum.

nero120 commented 4 years ago

Try running the containers individually using docker (not docker-compose). Start with mongodb, then api. Keep things simple and see what breaks. It sounds to me like this is a general docker issue though, not an xbrowsersync issue. You should be able to take the vanilla api docker compose yml and run it like everyone else.

The-Inamati commented 4 years ago

OK. So I reviewed everything and the container is now running. However it's behind traefik v2 and the webpage appears without formatting. Any ideas?

The-Inamati commented 4 years ago

Neverming. Got it. Thanks.

nero120 commented 4 years ago

Glad to hear you got it sorted @The-Inamati!

Rinma commented 3 years ago

@The-Inamati and what was the solution to this problem?