Instead of managing the containers with the docker
command, you may use Docker Compose to handle them.
First, install the docker-compose
command:
sudo apt-get install docker-compose
Previously we run:
docker run --name mariadb-container-with-existing-external-volume -v$(pwd)/datastore-mysql:/var/lib/mysql -it -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb
and
docker run -itd --name php-app -p80:80 --link mariadb-container-with-existing-external-volume php-app
We now create a file called docker-compose.yml
:
version: '2'
services:
php-app:
image: php-app
ports:
- '80:80'
links:
- mariadb-container-with-existing-external-volume
mariadb-container-with-existing-external-volume:
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD=my-secret-pw
volumes:
- './datastore-mysql:/var/lib/mysql'
For each of the docker run
commands, you add an entry under services
, containing the appropriate options. The various options are described in the Compose file reference.
Having this file, you can run both containers with a simple command:
docker-compose up
Then again, check localhost/db.php in the browser.