title: docker-compose Unknown MySQL server host 'mysql' (airflow)
body: <p>I try to create my Airflow service. When I run three dockers separately (without <code>docker-compose</code>) everything works but when I try to do the same using <code>docker-compose</code> I get the error. It seems that airflow doesn't see database. </p>
  
  <p><code>docker-compose.yml</code></p>
  
  <pre><code>version: '2'
  
  services:
  
    mysql:
      image: "someregisty/mysql"
      environment:
       - MYSQL_ROOT_PASSWORD=somepassword
  
    redis:
      image: "someregisty/redis"
  
    airflow:
      image: "someregisty/airflow"
      volumes:
       - ./dags:/home/airflow/dags
       - ./logs:/home/airflow/logs
       - ./config/airflow.cfg:/home/airflow/airflow.cfg 
       - ./config/resolv.conf:/etc/resolv.conf
       - ./config/somekeytab.keytab:/home/airflow/airflow.keytab 
      ports:
       - "8484:8080"
      environment:
       - AIRFLOW__CELERY__BROKER_URL=redis://redis:6379/0
       - AIRFLOW__CELERY__CELERY_RESULT_BACKEND=db+mysql://root:somepassword@mysql/airflow
       - AIRFLOW__CORE__SQL_ALCHEMY_CONN=mysql://root:somepassword@mysql/airflow
       - AIRFLOW__CORE__AIRFLOW_HOME=/home/airflow
       - AIRFLOW__CORE__DAGS_FOLDER=/home/airflow/dags/
       - AIRFLOW__CORE__PLUGINS_FOLDER=/home/airflow/plugins/
       - AIRFLOW_SCHEDULER=true
       - AIRFLOW_WEBSERVER=true
       - AIRFLOW_WORKER=true
       - AIRFLOW_KERBEROS=true
       - AIRFLOW_KERBEROS_PRINCIPAL=prj_bdc@DCWP.PL
       - AIRFLOW__KERBEROS__CCACHE=/home/airflow/kerberos.keytab.cache
       - KRB5CCNAME=/home/airflow/kerberos.keytab.cache
      depends_on:
       - redis
       - mysql
  </code></pre>
  
  <p>I run</p>
  
  <pre><code>docker-compose up -d
  docker-compose exec mysql mysql -u root --password=somepassword -e "create database airflow"
  </code></pre>
  
  <p>and that works ok. Then I run</p>
  
  <pre><code>docker-compose exec airflow airflow initdb
  </code></pre>
  
  <p>And I get </p>
  
  <pre><code>[2017-09-28 16:34:36,100] {__init__.py:57} INFO - Using executor CeleryExecutor
  /usr/lib/python2.7/site-packages/airflow/utils/helpers.py:406: DeprecationWarning: Importing BaseSensorOperator directly from &lt;module 'airflow.operators' from '/usr/lib/python2.7/site-packages/airflow/operators/__init__.pyc'&gt; has been deprecated. Please import from '&lt;module 'airflow.operators' from '/usr/lib/python2.7/site-packages/airflow/operators/__init__.pyc'&gt;.[operator_module]' instead. Support for direct imports will be dropped entirely in Airflow 2.0.
    DeprecationWarning)
  DB: mysql://root:***@mysql/airflow
  [2017-09-28 16:34:36,666] {db.py:287} INFO - Creating tables
  Traceback (most recent call last):
    File "/usr/bin/airflow", line 28, in &lt;module&gt;
      args.func(args)
    File "/usr/lib/python2.7/site-packages/airflow/bin/cli.py", line 951, in initdb
      db_utils.initdb()
    File "/usr/lib/python2.7/site-packages/airflow/utils/db.py", line 106, in initdb
      upgradedb()
    File "/usr/lib/python2.7/site-packages/airflow/utils/db.py", line 294, in upgradedb
      command.upgrade(config, 'heads')
    File "/usr/lib/python2.7/site-packages/alembic/command.py", line 174, in upgrade
      script.run_env()
    File "/usr/lib/python2.7/site-packages/alembic/script/base.py", line 416, in run_env
      util.load_python_file(self.dir, 'env.py')
    File "/usr/lib/python2.7/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
      module = load_module_py(module_id, path)
    File "/usr/lib/python2.7/site-packages/alembic/util/compat.py", line 79, in load_module_py
      mod = imp.load_source(module_id, path, fp)
    File "/usr/lib/python2.7/site-packages/airflow/migrations/env.py", line 86, in &lt;module&gt;
      run_migrations_online()
    File "/usr/lib/python2.7/site-packages/airflow/migrations/env.py", line 73, in run_migrations_online
      with connectable.connect() as connection:
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 2091, in connect
      return self._connection_cls(self, **kwargs)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 90, in __init__
      if connection is not None else engine.raw_connection()
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 2177, in raw_connection
      self.pool.unique_connection, _connection)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 2151, in _wrap_pool_connect
      e, dialect, self)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1465, in _handle_dbapi_exception_noconnection
      exc_info
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
      reraise(type(exception), exception, tb=exc_tb, cause=cause)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
      return fn()
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 328, in unique_connection
      return _ConnectionFairy._checkout(self)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 766, in _checkout
      fairy = _ConnectionRecord.checkout(pool)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 516, in checkout
      rec = pool._do_get()
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 1138, in _do_get
      self._dec_overflow()
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
      compat.reraise(exc_type, exc_value, exc_tb)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 1135, in _do_get
      return self._create_connection()
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 333, in _create_connection
      return _ConnectionRecord(self)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 461, in __init__
      self.__connect(first_connect_check=True)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/pool.py", line 651, in __connect
      connection = pool._invoke_creator(self)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect
      return dialect.connect(*cargs, **cparams)
    File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 393, in connect
      return self.dbapi.connect(*cargs, **cparams)
    File "/usr/lib64/python2.7/site-packages/MySQLdb/__init__.py", line 86, in Connect
      return Connection(*args, **kwargs)
    File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 204, in __init__
      super(Connection, self).__init__(*args, **kwargs2)
  sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (2005, "Unknown MySQL server host 'mysql' (0)")
  </code></pre>
  
  <p>I don't know what is wrong. Maybe you could help me? :)</p>
  
  <p>Versions of docker and docker-compose are</p>
  
  <pre><code>Docker version 1.12.6, build 96d83a5/1.12.6
  docker-compose version 1.9.0, build 2585387
  </code></pre>