title: How to link two containers using docker-compose
body: <p>At the moment I have two containers which I build from an image and then link the two:</p>
  
  <p>For example:</p>
  
  <pre><code>#mysql
  docker build -t my/mysql docker-mysql
  docker run -p 3306:3306 --name mysql -d my/mysql:latest
  
  #webapp
  docker build -t my/tomcat:7.0 tomcat/7.0
  docker run -d --link mysql --name tomcat7 my/tomcat:7.0
  </code></pre>
  
  <p>Since I'm linking the <code>webapp</code> container with <code>mysql</code> container, the <code>webapp</code> container gets a <code>MYSQL_PORT_3306_TCP_ADDR</code> environment variable created. I use this environment variable to then connect to the mysql database in my <code>jdbc</code> string. </p>
  
  <p>All of this works fine but now I'd like to use <code>docker-compose</code> so that everything can be built and ran from one command. </p>
  
  <p>However, while playing with docker-compose I'm noticing that it prefixes <code>docker_</code> to the image name and furthermore deprecates the <code>link</code> option. </p>
  
  <p><strong>Question</strong></p>
  
  <p>How would the above build/run commands translate to docker-compose yml file such that the webapp container can connect to the mysql container for jdbc. </p>