Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depends_on rabbitmq to docker compose file #74

Closed
tleyden opened this issue Sep 29, 2016 · 19 comments
Closed

Add depends_on rabbitmq to docker compose file #74

tleyden opened this issue Sep 29, 2016 · 19 comments

Comments

@tleyden
Copy link
Owner

tleyden commented Sep 29, 2016

As mentioned in #66 (comment), the docker compose file needs:

    depends_on:
      - "rabbitmq"

after that, the changes from https://github.com/tleyden/open-ocr/pull/65/files will work.

@GeorgeAnanthSoosai
Copy link

Can you please give me the updated compose file ?

@wicope
Copy link

wicope commented Sep 30, 2016

#37

In theory, I have not tested.

https://docs.docker.com/compose/startup-order/

https://docs.docker.com/compose/compose-file/#upgrading
https://docs.docker.com/compose/link-env-deprecated/

Posible solution 1

version: '2'

services:
  app:
    image: qq/ls
    depends_on:
      - db

  db:
    image: hh

run with:
docker-compose up -d app

Posible solution 2

version: '2'

services:
  app:
    image: qq/ls

  db:
    image: hh

run with:
docker-compose up -d db app

Now the problem is:
first rabbitmq must be running, and after strokewidthtransform openocrworker and openocr connet to rabbitmq.
I see the sleep for run, for wait to rabbitmq working.
open-ocr-httpd
open-ocr-preprocessor
open-ocr-worker

My test are with:
docker-compose up -d rabbitmq strokewidthtransform openocr;sleep 60;docker-compose up -d openocrworker
so I have only problems openocrworker.

It's only a first idea to try. Increase the sleep of open-ocr-worker and replace links tag by depends_on tag on docker-compose.yml and run with: docker-compose up -d strokewidthtransform openocr openocrworker

Regards

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

@wicope what about this? https://gist.github.com/tleyden/35a75b365fcb7afb59a1f59eb7cafd2e

Note the "dependency chain" where openocr depends on rabbitmq, and everything else depends on openocr. (also, wrapper scripts with sleeps removed)

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

That didn't work for me

$ docker-compose start
ERROR: Validation failed in file './docker-compose.yml', reason(s):
Unsupported config option for openocr: 'depends_on'
Unsupported config option for openocrworker: 'depends_on'
Unsupported config option for strokewidthtransform: 'depends_on'
tleyden_macbook:docker-compose tleyden$ docker-compose --version
docker-compose version 1.6.0, build d99cad6

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

I upgraded docker-compose, same error

$ docker-compose start
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for openocr: 'depends_on'
Unsupported config option for openocrworker: 'depends_on'
Unsupported config option for strokewidthtransform: 'depends_on'
tleyden_macbook:docker-compose tleyden$ docker-compose --version
docker-compose version 1.8.1, build 878cff1

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

Switched to https://gist.github.com/tleyden/872475942bf7e70ce34e6f39f1b388db since links includes depends_on behavior, but still not working:

$ docker-compose up
Creating dockercompose_rabbitmq_1
Creating dockercompose_openocr_1
Creating dockercompose_strokewidthtransform_1
Creating dockercompose_openocrworker_1
Attaching to dockercompose_rabbitmq_1, dockercompose_openocr_1, dockercompose_openocrworker_1, dockercompose_strokewidthtransform_1
rabbitmq_1              | =ng RabbitMQ with a preset password
openocrworker_1         | 1325179 OCR_WORKER: Creating new OCR Worker
openocrworker_1         | 15:19:01.327655 OCR_WORKER: Run() called...
openocrworker_1         | 15:19:01.327693 OCR_WORKER: dialing "amqp://admin:Phaish9ohbaidei6oole@rabbitmq/"
openocrworker_1         | 15:19:01.328288 OCR_WORKER: error connecting to rabbitmq dial tcp 172.17.0.2:5672: connection refused
openocrworker_1         | 15:19:01.328312 PANIC: Error running worker: dial tcp 172.17.0.2:5672: connection refused -- main.main() at main.go:36
openocrworker_1         | panic: Error running worker: dial tcp 172.17.0.2:5672: connection refused
openocrworker_1         |
openocrworker_1         | goroutine 1 [running]:
openocrworker_1         | runtime.panic(0x628cc0, 0xc210035a20)
rabbitmq_1              | ========================================================================
openocrworker_1         |   /usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
rabbitmq_1              | You can now connect to this RabbitMQ server using, for example:
openocrworker_1         | github.com/couchbaselabs/logg.LogPanic(0x738f90, 0x18, 0x7f8035852dc0, 0x1, 0x1)
rabbitmq_1              |
openocrworker_1         |   /opt/go/src/github.com/couchbaselabs/logg/logg.go:136 +0xec
rabbitmq_1              |     curl --user admin:<RABBITMQ_PASS> http://<host>:<port>/api/vhosts
openocrworker_1         | main.main()
rabbitmq_1              |
openocrworker_1         |   /opt/go/src/github.com/tleyden/open-ocr/cli-worker/main.go:36 +0x298
rabbitmq_1              | ========================================================================
openocrworker_1         |
openocrworker_1         | goroutine 5 [syscall]:
openocrworker_1         | runtime.goexit()
openocrworker_1         |   /usr/lib/go/src/pkg/runtime/proc.c:1394
dockercompose_openocrworker_1 exited with code 2
rabbitmq_1              |
rabbitmq_1              |       RabbitMQ 3.6.1. Copyright (C) 2007-2016 Pivotal Software, Inc.
rabbitmq_1              |   ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
rabbitmq_1              |   ##  ##
rabbitmq_1              |   ##########  Logs: /var/log/rabbitmq/rabbit@a3a3dbbcd645.log
rabbitmq_1              |   ######  ##        /var/log/rabbitmq/rabbit@a3a3dbbcd645-sasl.log
rabbitmq_1              |   ##########
    ^CGracefully stopping... (press Ctrl+C again to force)

@wicope
Copy link

wicope commented Sep 30, 2016

docker-compose has two version of file.yml

when you put in file.yml version tag and services tag like:

version: '2'
services:
  app:
    image: qq/ls

then you are using version 2 of docker-compose.

For use version 1 of docker-compose you not must have version tag and services tag like:

app:
  image: qq/ls

For version 1 of docker-compose you have links tag and not depends_on tag.
For version 2 of docker-compose you have depends_on tag and not links tag.

https://docs.docker.com/compose/compose-file/#upgrading
Upgrading
In the majority of cases, moving from version 1 to 2 is a very simple process:

  1. Indent the whole file by one level and put a services: key at the top.
  2. Add a version: '2' line at the top of the file.
    https://docs.docker.com/compose/link-env-deprecated/

I think that depends_on tag launches first the container of dependence and later the container is released. The problem of depends_on is that no does not wait for the service is initialized. For resolve this there are some ways on https://docs.docker.com/compose/startup-order/

Regards

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

Thanks, I tried v2 https://gist.github.com/tleyden/b39bc392e2beade385b978c4c9f712b1

Same error.

@wicope
Copy link

wicope commented Sep 30, 2016

Hi

Same error? It's because you use links with version 2 of docker-compose.yml

https://docs.docker.com/compose/link-env-deprecated/
Note: Environment variables are no longer the recommended method for connecting to linked services. Instead, you should use the link name (by default, the name of the linked service) as the hostname to connect to. See the docker-compose.yml documentation for details.
Environment variables will only be populated if you’re using the legacy version 1 Compose file format.

For version 1 of docker-compose you have links tag (not depends_on tag)

    links:
      - rabbitmq

For version 2 of docker-compose you have depends_on tag (not links tag)

    depends_on:
      - "rabbitmq"

Regards

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

For version 2 of docker-compose you have depends_on tag and not links tag.

Ok, sorry I skimmed that. Ok I will retest with v2 + depends_on

@tleyden
Copy link
Owner Author

tleyden commented Sep 30, 2016

@wicope changed to use depends_on, still not working .. https://gist.github.com/tleyden/5d86581fe4293248aebee52705fb9ee1

I think this will need to use https://github.com/vishnubob/wait-for-it or dockerize as mentioned in the docs you posted. Thanks!

@wicope
Copy link

wicope commented Oct 1, 2016

Yes you see the error:
dockercompose_openocrworker_1 exited with code 2
so we have problems with openocrworker.

Please can test:
docker-compose up -d rabbitmq strokewidthtransform openocr;sleep 60;docker-compose up -d openocrworker
Should be working

I think that depends_on tag launches first the container of dependence and later the container is released. The problem of depends_on is that no does not wait for the service is initialized. For resolve this there are some ways on https://docs.docker.com/compose/startup-order/
Well, yes, if the last command work then is another bad way with sleep.

Choose:

  • sleep: no build a new container docker. I think that work.
  • wait-for-it, dockerize... need test... build a new container docker. I think is better.

Regards

@tleyden
Copy link
Owner Author

tleyden commented Oct 1, 2016

wait-for-it, dockerize... need test... build a new container docker. I think is better.

Yeah, agreed

@tleyden
Copy link
Owner Author

tleyden commented Oct 1, 2016

docker-compose up -d rabbitmq strokewidthtransform openocr;sleep 60;docker-compose up -d openocrworker

Kinda defeats a lot of the purpose of compose, but thanks for posting the workaround!

@GeorgeAnanthSoosai
Copy link

great!!.. I was able to build it on my windows machine now.. thanks for your help!!!..

@kampta
Copy link

kampta commented Nov 12, 2016

Had same error; changes that I had to do -

moved docker-compose.yml to version 2; openocr depends on rabbitmq, and everything else depends on openocr

Gist: https://gist.github.com/kampta/a43413b64a1696b26673eca9ef8d640b

@tleyden
Copy link
Owner Author

tleyden commented Nov 14, 2016

@kampta thanks for the contribution!

@matzschmanski
Copy link

i added a sleep in the command because i could not get it to run in any other way - yes workarround but works for me https://gist.github.com/matzschmanski/4c96d48b2240dc90ee520d17c4bf8ba6

@tleyden
Copy link
Owner Author

tleyden commented Oct 10, 2017

@tleyden tleyden closed this as completed Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants