How to use Dockerfile to link main container to a db container?

Docker has a quite convenient way to link the main container to a db container with a command like:

docker run --link db:db user/main

This is very convenient already. However, I believe it’s still clumsy compared to a command like:

  • Docker running out of memory when loading large sql dump
  • How can I boot a swarm of 50 machines with docker-machine?
  • How to control fluentd log tag from Docker
  • How to mount RBD image (ceph) to default data directory of mysql docker
  • How to edit file after I shell to a docker container?
  • Docker how to report phpunit test that run inside container
  • docker run user/ultra

    where ultra is a container that is already linking the main container to the db container.

    Is that possible that I can achieve this by writing a good Dockerfile.

    I suppose I can start the Dockerfile with

    FROM user/main 

    but how do I get the second container involved and then link them with Dockerfile?


  • Docker \ how to pull only changed images
  • mounting a pseudo-tty in a docker container
  • Docker on Azure .Net Core WebApi with continuous deployment - did it work?
  • Docker: how do I find localhost's password on Windows 8.1
  • Docker: Error response from daemon: rpc error: code = 2 desc = “oci runtime error: exec format error”
  • How to avoid copying all the docker context directory?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.