title: Python error only in docker environment (Name or service not known)
body: <p>I've running a python script in a docker container, which should send me an email with its results.</p>
  
  <p>On the local machine without an docker environment it works, but in the container it gives me this:</p>
  
  <pre><code>grab_immo    | Traceback (most recent call last):
  grab_immo    |   File "./main.py", line 236, in &lt;module&gt;
  grab_immo    |     main()
  grab_immo    |   File "./main.py", line 229, in main
  grab_immo    |     sendmail(item['link'], item['price'], item['titel'], item['description'])
  grab_immo    |   File "./main.py", line 76, in sendmail
  grab_immo    |     s = smtplib.SMTP(host=SMTP_HOST, port=SMTP_PORT)
  grab_immo    |   File "/usr/local/lib/python3.7/smtplib.py", line 251, in __init__
  grab_immo    |     (code, msg) = self.connect(host, port)
  grab_immo    |   File "/usr/local/lib/python3.7/smtplib.py", line 336, in connect
  grab_immo    |     self.sock = self._get_socket(host, port, self.timeout)
  grab_immo    |   File "/usr/local/lib/python3.7/smtplib.py", line 307, in _get_socket
  grab_immo    |     self.source_address)
  grab_immo    |   File "/usr/local/lib/python3.7/socket.py", line 707, in create_connection
  grab_immo    |     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  grab_immo    |   File "/usr/local/lib/python3.7/socket.py", line 748, in getaddrinfo
  grab_immo    |     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  grab_immo    | socket.gaierror: [Errno -2] Name or service not known
  grab_immo exited with code 0
  </code></pre>
  
  <p>the part causing the error:</p>
  
  <pre><code>def sendmail(link, price, titel, description):
      logger.info('Attempt to send mails with object %s', link)
      names, emails = get_contacts(newPath + 'contacts') # read contacts
      message_template = read_template(newPath + 'template')
  
      # set up the SMTP server
      s = smtplib.SMTP(host=SMTP_HOST, port=SMTP_PORT)
      s.starttls()
      s.login(MY_ADDRESS, PASSWORD)
  
      # For each contact, send the email:
      for name, email in zip(names, emails):
          msg = MIMEMultipart()       # create a message
  
          # add in the actual person name to the message template
          message = message_template.substitute(PERSON_NAME=name.title(), LINK=link, PRICE=price, TITEL=titel, DESCRIPTION=description)
  
          # setup the parameters of the message
          msg['From']=MY_ADDRESS
          msg['To']=email
          msg['Subject']="yyy"
  
          # add in the message body
          msg.attach(MIMEText(message, 'plain'))
  
          # send the message via the server set up earlier.
          s.send_message(msg)
          del msg
          logger.info('Mail sent to  %s', name)
  
      # Terminate the SMTP session and close the connection
      s.quit()
  </code></pre>
  
  <p>ENV part:</p>
  
  <pre><code>MY_ADDRESS = os.environ['MY_ADDRESS']
  PASSWORD = os.environ['PASSWORD']
  SMTP_HOST = os.environ['SMTP_HOST']
  SMTP_PORT = os.environ['SMTP_PORT']
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/58367480/dockerfile-added-files-wont-be-copied-to-volume">I had another problem before, but I dont think it's related</a></p>
  
  <p>Thanks for reading!</p>
  
  <p>edit: docker-compose part</p>
  
  <pre><code>environment:
      - MY_ADDRESS = yyy@yyy.com
      - PASSWORD = yyy
      - SMTP_HOST = smtp.strato.de
      - SMTP_PORT = 587
  </code></pre>
  
  <p>taken from <a href="https://www.strato.de/faq/mail/so-lauten-die-strato-e-mail-server/" rel="nofollow noreferrer">here</a></p>
  
  <p>dockerfile:</p>
  
  <pre><code>FROM python:3
  
  COPY grab_immo /grab_immo
  
  RUN mkdir /data
  
  ADD ./data/contacts /data
  ADD ./data/run.log /data
  ADD ./data/template /data
  
  VOLUME /data
  
  WORKDIR /grab_immo
  
  RUN pip install -r requirements.txt
  
  ENV MY_ADDRESS=value \
      PASSWORD=value \
      SMTP_HOST=value \
      SMTP_PORT=587
  
  CMD [ "python", "./main.py" ]
  </code></pre>
  
  <p>docker-compose.yml</p>
  
  <pre><code>---
  version: "2"
  services:
    grab_immo:
      build: .
      image: yyy/grab_immo
      container_name: grab_immo
      environment:
      - MY_ADDRESS = 'stuff'
      - PASSWORD = stuff
      - SMTP_HOST = smtp.strato.de
      - SMTP_PORT = 587
      volumes:
        - /home/yyy/grab_immo_config:/data
      restart: unless-stopped
  </code></pre>