0

I use the socketplane/openvswitch docker image. When I follow their instructions to build and execute OVS commands in a running container, everything works fine. However, when I try to build a bash script for running and executing OVS commands the container returns with

db.sock: Database connection failed (Connection refused)

Actually the problem is running the following commands in a terminal:

docker run -itd --cap-add NET_ADMIN [container-name]
docker exec $cid ovs-vsctl show

succeeds, but running same commands in a bash script does not.

This is my bash script:

#!/bin/bash
cid=$(docker run -itd --cap-add NET_ADMIN [container-name])
docker exec $cid ovs-vsctl show

Thanks

Daniel
  • 440
  • 4
  • 13
  • We can't answer this without more detail. At the very least a reference to what instructions you're following to cause the problem. And what (sequence of) commands you're running that error. – Sobrique Feb 12 '16 at 15:24
  • [ask] is a useful reference point for making a good question. Imagine I'm trying to reproduce your fault on my system. What would I need to do? – Sobrique Feb 12 '16 at 15:26
  • sorry, modified the question – Daniel Feb 12 '16 at 15:28

1 Answers1

0

My thought would be that the root of your problem is here:

docker run -itd

Because they're contradictory parameters.

  • -d says 'run in background`.
  • -it says 'run interactively, attach a tty.

So I would suggest that you try:

#!/bin/bash
cid=$(docker run -d --cap-add NET_ADMIN [container-name])
docker exec $cid ovs-vsctl show

Failing that, my second guess would be - the startup process of the container takes a little while. I get this when firing up kibana containers - it takes a few seconds to start, so I get 'permission denied' errors.

Try sticking a 'sleep' in there, as a simple test, but if that is the problem - you'll need to check the DB startup and see where you've 'got to'.

Failing that, you can "attach" to your container interactively, with docker exec -it <container> bash and run the command and troubleshoot directly.

Sobrique
  • 52,974
  • 7
  • 60
  • 101