Docker creates an isolated machine (container). Each container contains only one process (Apache or Mysql or another); And Dockerfile defines how to create an image.
Docker compose allows you to run, link, and configure bunch containers.
In your case, apache should know "where" mysql. And mysql needs to be woken up before running the apache container.
Dockerfile
defines a way to create an application image. The application image contains the application and a web browser.
FROM apache:php5.6 ADD /src /var/www/awesome_project
Then you need to create a docker build my_app:latest .
image docker build my_app:latest .
At this point you created the image and you need to run the application and link it to db
You have 2 ways to do this:
1) Own docker approach. you start the db container
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest
and after you need to run the application container (the image was previously created)
docker run --name my_app --link some-mysql:mysql -P -d my_app
at this stage we are working with the application. A bit is a simple thing because we make two long teams. If you need to copy the application to another computer, you need to execute this command exactly.
2) the way to create dockers allows you to create a configuration for running containers. It describes how to launch containers accurately.
A simple docker-compose.yml
config illustrates this approach
db: image: mysql environment: - MYSQL_USER=root - MYSQL_PASSWORD=root app: image: my_app:latest ports: - 80:80 depends_on: - db environment:
This configuration allows you to run 2 containers together, links and configure them.
This is a very simple example. and the advantages of using dockers do not seem obvious, but if you have 5+ containers, it is too difficult to combine them without layout.