HowTo build an Docker infrastructure

What :

An infrastructure based on Varnish + Nginx + PHP-FPM + MariaDB

On Docker Containers

Why :

For a personnal blog or website

 

How : Build,Ship, Run

(Because the what is famous , we won’t do it from Dockerfiles . We will use Dockerhub images)

Step 1:

mkdir p $HOME/data/webstack/conf $HOME/data/webstack/www

 

Step 2: install NGinx

docker pull nginx

Controle your image with docker images

Launch your container

docker run name webstack_nginx_1 v $HOME/data/webstack/www:/usr/share/nginx/html:ro p 8080:80 d nginx
You can control by open your navigator and try
http://youserver:8080
Our container name is  webstack_nginx_1, the port TCP/8080 of our host will be tranfer to the port TCP/80 of the container (default port for NGinx) and it assigne in readonly the directory volume : /usr/share/nginx/html to the host directory $HOME/data/www .
To test we create some static pages :
echo « My first page » > $HOME/data/webstack/www/index.html
echo « <?php phpinfo(); ?>«  > $HOME/data/webstack/www/phpinfo.php
You can also confirm tha everythnig work fine by using :
curl http://localhost:8080
it will say : « My first page »
Step 3 : PHP-FPM

docker pull jprjr/phpfpm

Let run the container :

docker run name webstack_php_01 p 9000:9000 d jprjr/phpfpm

 

Step 4 : Make them talk together

Docker option : –link

We will copy the nginx configfile to the host

docker cp webstack_nginx_1:/etc/nginx/nginx.conf $HOME/data/webstack/conf/nginx.conf

 

 

vi $HOME/data/webstack/conf/nginx.conf

 

Add the server part

 

daemon off;
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octetstream;
    log_format  main  ‘$remote_addr – $remote_user [$time_local] « $request » ‘
                      ‘$status $body_bytes_sent « $http_referer » ‘
                      ‘ »$http_user_agent » « $http_x_forwarded_for »‘;
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   /usr/share/nginx/html;
        #}
        # Pass PHP scripts to PHP-FPM
        location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    webstack_php:9000;
            #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    /srv/http$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }    
        # deny access to .htaccess files, if Apache’s document root
        # concurs with nginx’s one
        location ~ /\.ht {
            deny  all;
        }
    }
}

 

 

In our usecase we need that the nginx container webstack_nginx_1 can communicate with the PHP container (webstack_php_01).

We delete the existing containers

docker stop webstack_php_01 && docker rm webstack_php_01

docker stop webstack_nginx_1 && docker rm webstack_nginx_1

 

And we recreate them by using a docker-compose command

Before create a docker-compose.yml file

 

php:
image: jprjr/php-fpm
ports:
– « 9000:9000 »
volumes:
– $HOME/data/webstack/www:/srv/http

web:
image: nginx
ports:
– « 8080:80 »
volumes:
– $HOME/data/webstack/www:/usr/share/nginx/html
– $HOME/data/webstack/conf/nginx.conf:/etc/nginx.conf
links:
– php

 

Then run the command

docker-compose up

 

and try it :

curl http://localhost:8080

 

 

 

 

 

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook

waffle.io an automatic kanban report

WAFFLE.IO

Waffle creates a free project management solution from your existing GitHub Issues.

Track Your Work Automatically
Your Waffle board shows your GitHub Issues and Pull Requests in real time. Never wonder if an Issue is still in progress or not. Waffle listens to the actions in your workflow to know when work is finished and updates your status automatically.

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook

Otto a vagrant successor ?

oto

Otto is the single solution to develop and deploy any application, with first class support for microservices.

Otto automatically builds development environments without any configuration; it can detect your project type and has built-in knowledge of industry-standard tools to setup a development environment that is ready to go. When you’re ready to deploy, otto builds and manages an infrastructure, sets up servers, builds, and deploys the application.

With the growing trend of microservices, Otto knows how to install and configure service dependencies for development and deployment. It automatically exposes these dependencies via DNS for your application to consume.

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook