So, my personal favorite way to do this is to use a tool called docker-compose. It allows you to define a simple yaml file, and then you have access to some extra commands that are prefixed docker-compose. I.e. docker-compose build, docker-compose up, etc. that make it much more convenient than running a bunch of separate docker commands and remembering container names for linking of containers and whatnot.
To give an example to help understanding see this docker-compose.yaml. In this file, you can conveniently declare your services (in this case db, php, and ansible <- each of which will be a separate container), and how they depend on each other, the paths to the individual Dockerfile for each container (build), and other goodies.
You can also specify environment information for the container to use (again, for the docker-compose I linked to, you can see ports, volumes, and environment for specifying information the container needs). In the example docker-compose file, in the environment: section of the db: service, you can see that it was trivial to specify this information, and upon starting the container, those values will automatically be used when installing/setting up mysql. It can be truly easy to have a running/configured mysql that is linked to other containers with one command. also there are other environment variables you can specify for the container to use (each one usually comes with several) click here to see a list
Take a look at a docker set up I made for LAMP stack development here. I have a couple different ones in my own github, but if you search github, you can find a bunch of docker/docker-compose set ups. They helped me get comfortable with docker (and still sometimes do) when I need to review how to set something up.
A really helpful starting guide can be found here. Docker compose has single-handedly made my workflow much easier to understand/implement several times over. It's definitely worth a look.