Docker container as web backend. Topic is solved

Questions regarding the API
Application Programming Interface
ij3net
Posts: 2
Joined: Sat Aug 08, 2015 7:11 am

Docker container as web backend.

Postby ij3net » Thu Oct 27, 2016 8:54 pm

I'm create proxy template that build and run docker container and setup it as web backend for nginx. So i'm interesting if someone trying some similar?

In my case i use it for build and configure some specific php environment. Default user doc_root attached to container as a volume. And host installed mysql server connected to container via socket volume.

/usr/local/vesta/data/templates/web/nginx/docker.sh

Code: Select all

#!/bin/bash
# Changing public_html permission
user="$1"
domain="$2"
ip="$3"
home_dir="/home/$user"
docroot="$4"
port_prefix="3"
userid=`id -u $user`
port="$port_prefix$userid"
#chmod 755 $docroot
mkdir -p $home_dir/docker/log
cp -R -a /usr/local/vesta/data/templates/web/skel/docker/* $home_dir/docker
echo "/usr/local/vesta/data/templates/web/nginx/docker/default.sh was running with user $user and $home_dir and doc_root $docroot" > $home_dir/docker.flag
sed -i "s/11080/$port/" $home_dir/conf/web/nginx.conf
echo "version: '2'
services:
  apache:
    build: ./apache
    ports:
      - $port:80
    volumes:
      - $docroot:/var/www/html
      - ./apache/date-timezone.conf:/etc/apache2/conf-enabled/date-timezone.conf
      - ./apache/encoding.conf:/etc/apache2/conf-enabled/encoding.conf
      - ./apache/php.ini:/usr/local/etc/php/php.ini
      - ./log:/var/log/apache2
      - /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
        stack: -1
    environment:
      - 'TZ=Asia/Vladivostok'
" > $home_dir/docker/docker-compose.yml
cd $home_dir/docker/
docker-compose -p $user down > $home_dir/docker/log/docker-compose_down.log
docker-compose -p $user up -d > $home_dir/docker/log/docker-compose_up.log
exit 0


/usr/local/vesta/data/templates/web/nginx/docker.tpl

Code: Select all

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    root        %docroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

    location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        proxy_pass  http://localhost:11080;

    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;
    include     %home%/%user%/conf/web/nginx.%domain%.conf*;
}


pottsonian
Posts: 1
Joined: Fri Nov 18, 2016 1:18 pm

Re: Docker container as web backend.

Postby pottsonian » Wed Nov 30, 2016 5:33 pm

Hi, did you take this into a production server? How is it going? Have you got any updated configs / code?
I am currently looking to do exactly the same. Have not started yet, still reading docker guides and getting my head around the best way to handle the persistent data volumes. Was thinking of rsyncing the vesta domain web folder with each docker volume web folder.

Also considering extending the add domain command to generate a docker, and set the configs and data volumes. So in principle you can setup a dockerised domain from the vesta front end. Could then add a few triggers to the vesta frontend to manage the container: reboot, reimage.

Happy wednesday

noogen
Posts: 41
Joined: Thu Jan 05, 2017 9:20 pm

Re: Docker container as web backend.  Topic is solved

Postby noogen » Tue Feb 14, 2017 4:35 am

Unlike the op, I implemented full docker for vestacp here: https://hub.docker.com/r/niiknow/vestacp/

Since it's a monolithic image, it does defeat the purpose of docker/microservice design. Of course, it was for a different purpose. I just want to host with VESTA but didn't want to blow away or mess up my external VPS setup. I currently run several of these in Production.


Return to “Scripting / API”



Who is online

Users browsing this forum: Bing [Bot] and 2 guests