About
The automated build docker LEMP
image “linuxconfig/lemp” can be used as a testing and also as a production environment for a dynamic PHP applications. It comprises of Debian GNU/Linux, lightweight and yet powerful Nginx webserver, MariaDB relational database management system and PHP scripting language.
Deployment
The deployment of “linuxconfig/lemp” docker image is a fairly simple procedure. Let’ start by creating a sample PHP website with a MariaDB connection handle:
<?php $dbh = mysqli_connect('localhost', 'admin', 'pass'); if (!$dbh) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully to MariaDB database'; mysqli_close($dbh); ?>
Save the above code into index.php
file and within a new html
directory. Alternatively,html
directory may contain your desired PHP application:
$ mkdir html $ vi html/index.php $ ls html/ index.php
At this stage we are ready to deploy “linuxconfig/lemp” docker image:
$ sudo docker run --name=lemp -dP -v $PWD/html:/var/www/html linuxconfig/lemp fa3be4d751519fe5e28b022f571b18a79025a7db35865d1de46e161067e99bd9
By executing the above command we have created and started a new docker container lemp
. At the same time we have also mounted our website development directory html
as nginx’s root directory. Both, MariaDB and Nginx ports are now bound to a host system’s random port. The both local ports can now be used to access both MariaDB and Nginx services :
$ sudo docker port lemp 80/tcp -> 0.0.0.0:49156 3306/tcp -> 0.0.0.0:49155
Nginx Access
At this stage Nginx webserver and our website can be accessed via ports given by $ sudo docker port lemp
command. Use command line or your browser to navigate to http://localhost:49156
URL:
$ curl -i http://localhost:49156 HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Sun, 10 May 2015 01:12:08 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Connected successfully to MariaDB database
MariaDB Access
The MariaDB database can be accessed via admin
user and default password pass
. As previously, first we need to obtain the host system port number linked to MariaDB database within a docker image by using $ sudo docker port lemp
command. Next, we can connect to database:
mysql -uadmin -ppass -h 127.0.0.1 -P49155 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.1.23-MariaDB-8 Debian 9.0 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
Additional Information
Reset MariaDB user password
The below command will set a new password 123
for theadmin
user :
SET PASSWORD FOR 'admin'@'%' = PASSWORD('123');
Restart lemp stack
$ sudo docker exec lemp service supervisor restart
Container Access
While your lemp
container is running it can be access by:
$ sudo docker exec -it lemp /bin/bash root@733ae4bebf83:/#