title: How to resolve exceptions.OSError: [Errno 1] Operation not permitted (docker container)?
body: <p>I am trying to scan BLE devices with <a href="https://github.com/IanHarvey/bluepy/blob/master/docs/scanner.rst" rel="nofollow noreferrer"><strong>bluepy</strong></a>. My <strong>scan.py</strong> code is --</p>
  
  <pre><code>from bluepy.btle import Scanner, DefaultDelegate
  
  class ScanDelegate(DefaultDelegate):
      def __init__(self):
          DefaultDelegate.__init__(self)
  
      def handleDiscovery(self, dev, isNewDev, isNewData):
          if isNewDev:
              print "Discovered device", dev.addr
          elif isNewData:
              print "Received new data from", dev.addr
  
  # prepare scanner
  scanner = Scanner().withDelegate(ScanDelegate())
  
  # scan for 5 seconds
  devices = scanner.scan(5.0)
  
  for dev in devices:
      print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
      for (adtype, desc, value) in dev.getScanData():
          print "  %s = %s" % (desc, value)
  </code></pre>
  
  <p>According to the documentation (mentioned at the very last as Note) -- </p>
  
  <pre><code>(1) LE scanning must be run as root
  </code></pre>
  
  <p>That means we need to run the script with <strong><code>sudo</code></strong>. I run it as --</p>
  
  <pre><code>sudo python scan.py
  </code></pre>
  
  <p>Basically <strong>bluepy-helper</strong> requires the <strong><code>sudo</code></strong> to scan. It is required set the capabilities for <strong>blupe-helper</strong> to run the code without <strong><code>sudo</code></strong>. According to <a href="https://github.com/IanHarvey/bluepy/issues/190" rel="nofollow noreferrer">the solution</a>, I did -- </p>
  
  <pre><code>sudo setcap 'cap_net_raw,cap_net_admin+eip' /usr/local/lib/python2.7/site-packages/bluepy/bluepy-helper
  </code></pre>
  
  <p>From the Terminal, the scan code is now run without <strong><code>sudo</code></strong> like --</p>
  
  <pre><code>python scan.py
  </code></pre>
  
  <p>Finally, I made a Dockerfile --</p>
  
  <pre><code>FROM arm32v7/python:2.7.15-jessie
  WORKDIR /usr/app/gfi_ble
  COPY . /usr/app/gfi_ble
  RUN chmod 755 ./setcap_for_bluepy_helper.sh
  RUN pip install -r requirements.txt
  CMD ["./setcap_for_bluepy_helper.sh", "--", "python", "src/scan.py"]
  </code></pre>
  
  <p>The content of the <strong>setcap_for_bluepy_helper.sh</strong> is --</p>
  
  <pre><code>#!/bin/bash
  cmd="$@"
  &gt;&amp;2 setcap 'cap_net_raw,cap_net_admin+eip' /usr/local/lib/python2.7/site-packages/bluepy/bluepy-helper
  exec $cmd
  </code></pre>
  
  <p>The image is created successfully but when I run the container I am getting the error like -- </p>
  
  <pre><code>Creating con_gfi_ble ... done
  Attaching to con_gfi_ble
  con_gfi_ble | 2019-01-12 23:06:24+0000 [-] Unhandled Error
  con_gfi_ble |   Traceback (most recent call last):
  con_gfi_ble |     File "/usr/app/gfi_ble/src/scan.py", line 17, in new_devices
  con_gfi_ble |       devices = scanner.scan(5.0)
  con_gfi_ble |     File "/usr/local/lib/python2.7/site-packages/bluepy/btle.py", line 852, in scan
  con_gfi_ble |       self.start(passive=passive)
  con_gfi_ble |     File "/usr/local/lib/python2.7/site-packages/bluepy/btle.py", line 789, in start
  con_gfi_ble |       self._startHelper(iface=self.iface)
  con_gfi_ble |     File "/usr/local/lib/python2.7/site-packages/bluepy/btle.py", line 284, in _startHelper
  con_gfi_ble |       preexec_fn = preexec_function)
  con_gfi_ble |     File "/usr/local/lib/python2.7/subprocess.py", line 394, in __init__
  con_gfi_ble |       errread, errwrite)
  con_gfi_ble |     File "/usr/local/lib/python2.7/subprocess.py", line 1047, in _execute_child
  con_gfi_ble |       raise child_exception
  con_gfi_ble |   exceptions.OSError: [Errno 1] Operation not permitted
  con_gfi_ble | 
  </code></pre>
  
  <p><strong><em>Question:</em></strong> <em>What does exceptions.OSError: [Errno 1] Operation not permitted?</em> </p>
  
  <p>My code is fine when I run it from Terminal. What's wrong with the container? Any idea! </p>