machinebox / issues

Machine Box issues, bugs and feature requests
2 stars 0 forks source link

facebox: Box not ready using Docker Compose #4

Closed cgarciaarano closed 7 years ago

cgarciaarano commented 7 years ago

facebox v1 (7a1de89)

I'm pretty sure that the problem is in my setup, as it works when running as a standalone container, but maybe you can help me.

I have a docker-compose.yml file which uses facebox and an API adaptor I'm developing:

version: "2"

services:
  myapi:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - MACHINEBOX_URL=http://facebox:8080/facebox/check
      - MACHINEBOX_TIMEOUT=1
      - THRESHOLD=0.7
      - PATH_IMG=/tmp
      - DEBUG=True
    volumes:
      - .:/opt/app
    ports:
      - "8081:8080"
    command: python app.py

  facebox:
    image: machinebox/facebox:latest
    environment:
      - MB_KEY=SECRET
    ports:
      - "8080:8080"

It starts normally, but after the /info says the box is ready

/opt/app # curl http://faceboxbox:8080/info
{
        "success": true,
        "name": "facebox",
        "version": 1,
        "build": "7a1de89",
        "status": "ready"
}

any call to the API says that the box isn't ready yet:

 curl -H 'Content-Type: application/json' -d '{"url":"https://machinebox.io/samples/faces/thebeatles.jpg"}' http://facebox:8080/facebox/check
faceClient call error: box is not ready, try again later

As I said, running it using Docker directly (docker run -p 8080:8080 -e "MB_KEY=$MB_KEY" machinebox/facebox) works.

There are differencies in how Docker start containers in Compose. For example, in Compose v2 Docker creates a user-defined network, whereas docker run ... by default uses the bridged network. Besides of this, I don't get what's happening here.

It's reproducible defining only one facebox service in the ´docker-compose` file, and it happens with nudebox as well (and probably the other boxes). Anyway, maybe is a setup issue.

Do you have any idea what could be causing this?

dahernan commented 7 years ago

I haven't try to use docker compose so much, I'll have look today or tomorrow.

Usually when box is not ready means lack of enough memory to do the startup, we should put some INFO on the logs to make it explicit but is difficult to forecast, meanwhile if you can try to assign between 4GB-6GB, and let me know if it works, it would be great

cgarciaarano commented 7 years ago

Ok, I'll try.

I have already forced the bridged network without success, so it looks like is not network related.

cgarciaarano commented 7 years ago

What the heck, it works with 4GB!

I wonder why using 2 GBs and docker run ... works but it isn't with Compose. The memory footprint of Compose is negligible. Also, according to top the VM still has 1GB free

top2gb

Anyway, I'm closing the issue as it's not related to machinebox.

dahernan commented 7 years ago

Cool.

The startup is heavy, is a trade off between how quick it is starting up and how much memory consumes, after the startup it frees like a 1GB-2GB. It could be optimise but I did not spend any time on it.

You can adjust also the number of workers to control the memory footprint (MB_WORKERS=4 by default)

Let know what you are building by email, and if I can help you with anything. I'm interested in use cases :)

cgarciaarano commented 7 years ago

I also tried with MB_WORKERS=2, but same result, so it should be the startup as you said.

When I had something to show, you'll be the first to know 😊