title: Can't connect to MySQL server on 'localhost' ([Errno 99] Address not available)
body: <p>I got the above error when trying to connect to MariaDB from outside docker container. Below is my docker-compose.yml file:</p>
  <pre><code>version: '3'
  services:
      mariadb:
          image: mariadb
          ports:
              - &quot;127.0.0.1:3309:3306&quot;
          volumes: 
              - mariadb_volume:/var/lib/mysql
          environment: 
              MYSQL_ROOT_PASSWORD: mypassword
              MYSQL_DATABASE: mydatabase
              MYSQL_USER: myuser
              MYSQL_PASSWORD: mypassword
          networks:
              - fastapi_network
              
      fastapi-dev:
          build: 
              context: .
              dockerfile: Dockerfile
          image: fastapi-dev:latest
          container_name: fastapi-dev
          command: /start-reload.sh
          volumes: 
              - ./src:/app/src
          ports:
              - 5000:80
          depends_on:
              - mariadb
          networks:
              - fastapi_network
       
  volumes:
      mariadb_volume:
          driver: local
                        
  networks:
    fastapi_network:
      external: true
  </code></pre>
  <p>My DB config for DB connection is here:</p>
  <pre><code>class DbSettings(BaseSettings):
      db_username:str = 'myuser'
      db_password: str = 'mypassword'
      db_host: str = 'localhost'
      db_port: int = '3306'
      db_name: str = 'mydatabase'
  
      engine_echo = True
      session_autocommit = False
      session_autoflush = False
  
      @property
      def db_conn_str(self) -&gt; AnyUrl:
          return AnyUrl.build(
              scheme=&quot;mysql+pymysql&quot;,
              user=self.db_username,
              password=self.db_password,
              host=self.db_host,
              port=str(self.db_port),
              path=f&quot;/{self.db_name}&quot;
          )
  </code></pre>
  <p>After deploying the container with 'docker-compose up', I can see the server is completely up and run as below:</p>
  <pre><code>mariadb_1              | 2021-09-06  8:24:10 0 [Note] mysqld: ready for connections.
  mariadb_1              | Version: '10.6.4-MariaDB-1:10.6.4+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
  
  </code></pre>
  <p>Given that the server is running and accepting connections, I can't quite understand what went wrong with the code. Can someone advise me on this please?</p>