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 Debian apt Error Reading from Server
  • Unable to delete untagged images:Error response from daemon: Conflict, 511136 wasn't deleted FATA[0000] Error: failed to remove one or more images
  • Backup/Restore a dockerized PostgreSQL database
  • Amazon container registry login
  • run docker exec from swarm manager
  • is port not common for all the docker networks?
  • 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?

    Thanks.

  • Wercker crashes on MacOS with PANIC too many open files
  • Jenkins: Can't connect to Docker daemon
  • Docker undo rm container
  • Use Docker rather than native/homebrew on Mac?
  • Cannot use process substitution during docker build because bash goes into posix mode
  • Docker cannot run
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.