title: connect to mysql database from docker container
body: <p>I have this docker file and it is working as expected. I have php application that connects to mysql on localhost.</p>
  
  <pre><code># cat Dockerfile
  FROM tutum/lamp:latest
  RUN rm -fr /app
  ADD crm_220 /app/
  ADD crmbox.sql /
  ADD mysql-setup.sh /mysql-setup.sh
  EXPOSE 80 3306
  CMD ["/run.sh"]
  </code></pre>
  
  <p>When I tried to run the database as separate container, my php application is still pointing to localhost. When I connect to the "web" container, I am not able to connect to "mysql1" container.</p>
  
  <pre><code># cat docker-compose.yml
  web:
    build: .
    restart: always
    volumes:
      - .:/app/
    ports:
      - "8000:8000"
      - "80:80"
    links:
      - mysql1:mysql
  
  mysql1:
    image: mysql:latest
    volumes:
      - "/var/lib/mysql:/var/lib/mysql"
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: secretpass
  </code></pre>
  
  <p>How does my php application connect to mysql from another container?</p>
  
  <p>This is similar to the question asked here...</p>
  
  <p><a href="https://stackoverflow.com/questions/33001750/connect-to-mysql-in-a-docker-container-from-the-host">Connect to mysql in a docker container from the host</a></p>
  
  <p>I do not want to connect to mysql from host machine, I need to connect from another container.</p>