Currently WebServer consists of such images:
- Data-only container (based on official
debian:jessie
image) - Logrotate container (based on official
debian:jessie
image) - MariaDB (based on official
MariaDB
image) - Nginx (based on official
Nginx
image) - PHP-FPM (based on
nazarpc/php:fpm
image, which is official image + bunch of frequently used PHP extensions) - SSH (based on
phusion/baseimage
image, contains pre-installedcurl
,git
,mc
,wget
,php-cli
andcomposer
for your convenience) - PhpMyAdmin (based on
nazarpc/phpmyadmin
image, which is official php image with Apache2, where PhpMyAdmin was installed) - Ceph (based on upstream
ceph/daemon
image) - Consul (based on official
debian:jessie
image) - HAProxy (based on official
haproxy
image) - Backup container (based on official
debian:jessie
image) - Restore container (based on official
debian:jessie
image) - nazarpc/webserver-apps for ready to use applications that plays nicely with images mentioned above
If you find this project useful, consider supporting its development on patreon.com/nazarpc, this would help me a lot!
The most convenient way to use all this is Docker Compose
At first you'll need to create persistent data-only container that will store all files, databases, ssh keys and settings of all these things:
docker run --name example.com nazarpc/webserver:data-v1
NOTE: -v1
suffix here and in all other places is optional (there are also images without -v1
suffix and they are exactly the same), however, it is possible that in future images without suffixes become completely incompatible and -v2
suffixed images will be introduced, so you'd better be protected from upgrading to incompatible image rather than getting broken setup at some point in future (this might not happen ever, but still).
This container will start and stop immediately, that is OK.
After this create directory for your website, it will contain docker-compose.yml
file and potentially more files you'll need:
mkdir example.com
cd example.com
Now create docker-compose.yml
inside with following contents:
version: '2'
services:
data:
image: nazarpc/webserver:data-v1
volumes_from:
- container:example.com
logrotate:
image: nazarpc/webserver:logrotate-v1
restart: always
volumes_from:
- data
mariadb:
image: nazarpc/webserver:mariadb-v1
restart: always
volumes_from:
- data
nginx:
image: nazarpc/webserver:nginx-v1
links:
- php
# ports:
# - {ip where to bind}:{port on previous ip where to bind}:80
restart: always
volumes_from:
- data
php:
image: nazarpc/webserver:php-fpm-v1
links:
- mariadb:mysql
restart: always
volumes_from:
- data
# phpmyadmin:
# image: nazarpc/webserver:phpmyadmin-v1
# links:
# - mariadb:mysql
# restart: always
# ports:
# - {ip where to bind}:{port on previous ip where to bind}:80
ssh:
image: nazarpc/webserver:ssh-v1
restart: always
volumes_from:
- data
# ports:
# - {ip where to bind}:{port on previous ip where to bind}:22
# environment:
# PUBLIC_KEY: '{your public SSH key}'
Now customize it as you like, feel free to comment-out or remove mariadb
, php
or ssh
container if you have just bunch of static files, also you can uncomment phpmyadmin
container if needed.
When you're done with editing:
docker-compose up -d
That is it, you have whole WebServer up and running!
Also you might be interested in advanced examples with load balancing and scaling across cluster.
You can easily upgrade your WebServer to new version of software.
Using Docker Compose upgrade is very simple:
docker-compose pull
docker-compose up -d
All containers will be recreated from new images in few seconds.
Backup/restore images are not present in docker-compose.yml
, so if you're using them - pull them manually.
Alternatively you can pull all images manually:
docker pull nazarpc/webserver:data-v1
docker pull nazarpc/webserver:logrotate-v1
docker pull nazarpc/webserver:mariadb-v1
docker pull nazarpc/webserver:nginx-v1
docker pull nazarpc/webserver:php-fpm-v1
docker pull nazarpc/webserver:ssh-v1
docker pull nazarpc/webserver:backup-v1
docker pull nazarpc/webserver:restore-v1
And again in directory with docker-compose.yml
:
docker-compose up -d
To make backup you need to only backup volumes of data-only container. The easiest way to do that is using nazarpc/webserver:backup-v1
image:
docker run --rm --volumes-from=example.com -v /backup-on-host:/backup --env BACKUP_FILENAME=new-backup nazarpc/webserver:backup-v1
This will result in /backup-on-host/new-backup.tar
file being created - feel free to specify other directory and other name for backup file.
All other containers are standard and doesn't contain anything important, that is why upgrade process is so simple.
NOTE: You'll likely want to stop MariaDB instance before backup (it is enough to stop master node in case of MariaDB cluster with 2+ nodes)
Restoration from backup is not more difficult that making backup, there is nazarpc/webserver:restore-v1
image for that:
docker run --rm --volumes-from=example.com -v /backup-on-host/new-backup.tar:/backup.tar nazarpc/webserver:restore-v1
That is it, empty just created example.com
container will be filled with data from backup and ready to use.
SSH might be needed to access files from outside, especially with git.
Before you enter ssh container via SSH for the first time, you need to specify public SSH key (how to generate SSH keys).
The easiest way to do this is to define PUBLIC_KEY
environment variable in docker-compose.yml
.
Alternatively you can create file /data/.ssh/authorized_keys
and put your public key contents inside.
For example, you can do that from Midnight Commander file manager:
docker-compose run ssh mc
When public SSH key is added you should be able to access container as git
user:
ssh git@example.com
Internally all that matters is /data
directory - it contains all necessary files (or symlinks sometimes) for your convenience - here you can see files for Nginx and MariaDB, their logs and configs, PHP-FPM's config, SSH config and SSH keys directory.
That is all what will be persistent, everything else outside /data
will be lost during upgrade.
If you update some configuration - you don't need to restart everything, restart only specific service you need, for instance:
docker-compose restart nginx
MIT license, see license.txt