LEMP ( Linux, Nginx, MariaDB, PHP ) stack Docker image deployment

About

LEMP

Deployment

<?php $dbh = mysqli_connect('localhost', 'admin', 'pass'); if (!$dbh) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully to MariaDB database'; mysqli_close($dbh); ?>

index.php

html

html

$ mkdir html $ vi html/index.php $ ls html/ index.php

$ sudo docker run --name=lemp -dP -v $PWD/html:/var/www/html linuxconfig/lemp fa3be4d751519fe5e28b022f571b18a79025a7db35865d1de46e161067e99bd9

lemp

html

$ sudo docker port lemp 80/tcp -> 0.0.0.0:49156 3306/tcp -> 0.0.0.0:49155

Nginx Access

$ sudo docker port lemp

http://localhost:49156

$ 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

admin

pass

$ sudo docker port lemp

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

123

admin

SET PASSWORD FOR 'admin'@'%' = PASSWORD('123');

Restart lemp stack

$ sudo docker exec lemp service supervisor restart

Container Access

lemp

$ sudo docker exec -it lemp /bin/bash root@733ae4bebf83:/#

The automated build dockerimage “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.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:Save the above code intofile and within a newdirectory. Alternatively,directory may contain your desired PHP application:At this stage we are ready to deploy “linuxconfig/lemp” docker image:By executing the above command we have created and started a new docker container. At the same time we have also mounted our website development directoryas 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 :At this stage Nginx webserver and our website can be accessed via ports given bycommand. Use command line or your browser to navigate toURL:The MariaDB database can be accessed viauser and default password. As previously, first we need to obtain the host system port number linked to MariaDB database within a docker image by usingcommand. Next, we can connect to database:The below command will set a new passwordfor theuser :While yourcontainer is running it can be access by: