Here is an example of linking the official mongo and mysql image to a container build with this image:
docker run --name mimongo -d -v /home/mtx/Proyectos/php5-mongo/db:/data/db -p 27017:27017 mongo
docker run --name mimysql -e MYSQL_ROOT_PASSWORD=pepito -e MYSQL_USER=uuuuu -e MYSQL_PASSWORD=xxxxx -e MYSQL_DATABASE=midb -p 3306:3306 -d mysql:5.5
mysql -uroot -ppepito -h 127.0.0.1 -P 3306 midb < midb.sql
docker run --name miphp --link mimongo:mongo --link mimysql:mysql -v /home/mtx/Proyectos/php5-mongo/web:/var/www/html -d -p 80:80 smtx/php
test.php:
test1; // select a collection (analogous to a relational database's table) $collection = $db->colection_test; // add a record $document = array( "title" => "New One", "author" => "Nguyen Sy Thanh Son" ); $collection->insert($document); // add another record, with a different "shape" $document = array( "title" => "The Second One", "online" => true ); $collection->insert($document); // find everything in the collection $cursor = $collection->find(); // iterate through the results foreach ($cursor as $document) { echo $document["title"] . "\n"; } ?>Content type
Image
Digest
sha256:0b7ee2975…
Size
149.9 MB
Last updated
almost 11 years ago
docker pull smtx/php