title: Import error when running python script inside docker container?
body: <p>I am aiming to start a script that consume rabbitmq massages inside a container, here is the important details:</p>
  
  <p><code>messenger.py</code>,which is the script I am trying to run:</p>
  
  <pre><code>import pika
  from . import create_app
  
  class PikaMassenger():
  
      def __init__(self, *args, **kwargs):
          pass
  
      def consume(self, keys, callback):
          pass
  
      def __enter__(self):
          return self
  
  
      def __exit__(self, exc_type, exc_value, traceback):
          self.conn.close()
  
  
  
  def start_consumer(app):
  
      def callback(ch, method, properties, body):
          try:
              print("Event recieved %r" % body)
              with app.app_context():
                  pass
  
          except Exception as e:
              print("Consuming event %s failed: %s" % (method.routing_key, str(e)))
  
      with PikaMassenger() as consumer:
          consumer.consume(keys=['user.*', ], callback=callback)
  
  if __name__ == "__main__":
      app = create_app()
      start_consumer(app)
  </code></pre>
  
  <p>My <code>__init__.py</code> simply contains the app factory(<code>create_app</code>). My Dockerfile and docker-compose are:</p>
  
  <p><code>Dockerfile</code>: </p>
  
  <pre><code>FROM  python:3.6
  
  COPY requirements.txt /app/requirements.txt
  
  WORKDIR /app
  
  RUN pip install -r requirements.txt
  
  COPY . /app
  
  ENV SECRET_KEY dev
  
  
  ENV FLASK_APP run.py
  
  CMD  flask run
  </code></pre>
  
  <p><code>docker-compose.yaml</code>:   </p>
  
  <pre><code>  app:
      build:
        context: ./app
      expose:
        - "5000"
        - PYTHONUNBUFFERED=1
      restart: on-failure
  
    app_consumer:
      build:
        context: ./app
      command: python -m messenger.py
      environment:
        - PYTHONUNBUFFERED=1
      restart: on-failure
      depends_on:
        - rabbitmq 
  </code></pre>
  
  <p>So what I am trying to do is to run two containers with the same <code>Dockerfile</code>, while overriding the <code>command</code> parameter in one of them, I am aware that given the above details, error will occure: </p>
  
  <pre><code> File "/app/massenger.py", line 2, in &lt;module&gt;
       from . import create_app
   ImportError: attempted relative import with no known parent package
  </code></pre>
  
  <p>Perhaps I may have to change the working directory in <code>docker-compose.yaml</code>, or run my script in different way.  </p>
  
  <p>Please inform me if further details are needed, or if you want me to try something. </p>