title: cannot use mysql socket on host when using volumes
body: <p>I am coming from here:</p>
  
  <p><a href="https://stackoverflow.com/questions/56203642/how-to-run-docker-compose-with-host-network">How to run docker-compose with host network?</a></p>
  
  <p>the problem I realized is that <code>mysql_connect</code> uses sockets when <code>localhost</code> is entered as host. As a result, php on my host system, cannot find the socket because that socket is in the container.</p>
  
  <p>when I up with <code>compose-docker</code> I can read this</p>
  
  <blockquote>
    <p>Version: '5.6.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)</p>
  </blockquote>
  
  <p>so what I thought I logically do, is to enter on my host, the mysql_connect socket configuration in php, to point to <code>/var/run/mysqld/mysqld.sock</code></p>
  
  <p>but that is in my container, so it cannot find it.</p>
  
  <p>as a result, I tried mapping the container dir <code>/var/run/mysqld</code> to some host dir, so I can then use that host socket directory in my php.ini on my host.</p>
  
  <p>But:</p>
  
  <p>when I start up I get:</p>
  
  <blockquote>
    <p>Can't start server : Bind on unix socket: Permission denied</p>
    
    <p>Do you already have another mysqld server running on socket</p>
  </blockquote>
  
  <p>so mapping the socket folder somehow gives read write problems to the docker container. Is there any solution to this?</p>
  
  <p>my yml file is this:</p>
  
  <pre><code>version: '3.3'
  services:
    sciodb:
      container_name: sciodb
      image: mysql:5.6
      restart: always
      environment:
        MYSQL_DATABASE: 'db'
        # So you don't have to use root, but you can if you like
        MYSQL_USER: 'myuser'
        # You can use whatever password you like
        MYSQL_PASSWORD: 'test1234'
        # Password for root access
        MYSQL_ROOT_PASSWORD: 'test1234'
      ports:
        # &lt;Port exposed&gt; : &lt; MySQL Port running inside container&gt;
        - '3306:3306'
      expose:
        # Opens port 3306 on the container
        - '3306'
        # Where our data will be persisted
      volumes:
        - /home/myuser/nmyapp_db:/var/lib/mysql
        - /media/sf_vmwareshare:/var/vmwareshare
        - /home/myuser/nmyapp_socket:/var/run/mysqld
  </code></pre>