Public Repository

Last pushed: 2 years ago
Short Description
PHP with mongo extension.
Full Description

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:

<?php

// connect

$m = new MongoClient($_ENV["MONGO_PORT_27017_TCP_ADDR"]);

// select a database

$db = $m->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";
}

?>

Docker Pull Command
Owner
smtx

Comments (0)