A Practical Guide on Understanding Git Best Practices
Introduction In this post, we will learn about some of Best practices while…
March 06, 2018
Goto your command terminal.
Type:
docker run -d --name my-mongo mongo:latest
This will expose port: 27017 by default. You can connect to this mongo db instance by installing Robo 3T, a software for managing mongo db.
Run:
docker run -d -p 8020:80 --name php-apache php:5-apache
Note: This will run a php container, but in order to be able to connect to mongo db container, you need to link this container to mongo db container.
docker run -d -p 8020:80 --link my-mongo --name php-mongo-test php:5-apache
Now, you should be able to see two container running by typing: “docker ps” command.
There are two ways:
docker ps
Open a shell/bash in that container: (assumming 9da60559db80 is my container id)
docker exec -it 9da60559db80 bash
Now, you are into the shell terminal of php container. You will need to install php-mongo dependencies.
Run following commands:
apt-get update
apt-get install openssl libssl-dev libcurl4-openssl-dev
pecl install mongo
echo "extension=mongo.so" > /usr/local/etc/php/conf.d/mongo.ini
In above steps, we basically installed few dependencies required for mongo db connector, and installed mongo db php extension, and included that in php.ini list.
Note: Php container loads all ini file present in /usr/local/etc/php/conf.d/ directory
Now, you need to restart your container in order to load mongo db extension.
Restart your container:
docker stop 9da60559db80
docker start 9da60559db80
To test whether you have loaded mongo db extension correctly or not. Prepare a phpfile in /var/www/html directory say info.php, and put following content:
<?php
print phpinfo();
On your browser, try: localhost:8082/info.php
You should see a big html page showing php information, and installed extensions. Search for mongo, and it should show some results.
<?php
$connection = new MongoClient( "mongodb://my-mongo:27017" );
$collection = $connection->selectCollection('db-name', 'collection-name');
if (!$collection) {
echo 'not connected to collection';
exit;
}
$cursor = $collection->find();
foreach ($cursor as $doc) {
var_dump($doc);
}
Introduction In this post, we will learn about some of Best practices while…
Introduction In this step-by-step tutorial, we will setup strapi headless CMS…
Introduction You are having a form having multiple fields. When you render a…
Introduction This post is about syncing your mongodo database data to…
Introduction I was using Paypal payment on one of my website, and suddenly lot…
Introduction In this guide, We will learn about branching, handling conflict…
Introduction So you have a Django project, and want to run it using docker image…
Introduction It is very important to introduce few process so that your code and…
Introduction In this post, we will see a sample Jenkin Pipeline Groovy script…
Introduction We often require to execute in timed manner, i.e. to specify a max…
Introduction In some of the cases, we need to specify namespace name along with…
Introduction In most of cases, you are not pulling images from docker hub public…