Giter Club home page Giter Club logo

docker-webserver's Introduction

Webserver on docker containers

License: MIT Stand With Ukraine

Development process described in habr.com.

Webserver included:

  • MySQL
  • PHP
  • Nginx
  • msmtp
  • composer
  • cloud backups

Before starting

  1. Prepare server
  2. [optional] For SSL certificates up containers with nginx-proxy and acme-companion:
docker network create nginx-proxy-network

docker run --detach \
    --name nginx-proxy \
    --publish 80:80 \
    --publish 443:443 \
    --net nginx-proxy-network \
    --volume certs:/etc/nginx/certs \
    --volume vhost:/etc/nginx/vhost.d \
    --volume html:/usr/share/nginx/html \
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \
    nginxproxy/nginx-proxy

docker run --detach \
    --name nginx-proxy-acme \
    --net nginx-proxy-network \
    --volumes-from nginx-proxy \
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \
    --volume acme:/etc/acme.sh \
    --env "[email protected]" \
    nginxproxy/acme-companion

Where [email protected] is you contact email for sending emails with certs renew notifications.

Installation:

1. Clone repository

git clone [email protected]:a-kryvenko/docker-webserver.git .

2. Create copy of .env file:

cp .env.example .env

3. Modify .env, set up variables

Variables description
  • COMPOSE_FILE - which docker-compose files will be included;
  • SYSTEM_GROUP_ID - ID of host user group. Usually 1000;
  • SYSTEM_USER_ID - ID of host user. Usually 1000;
  • APP_NAME - url by which the site is accessible. For example, example.com or example.local for local development;
  • ADMINISTRATOR_EMAIL - email to which we send information about certificates;
  • DB_HOST - database host. By default db, but in the case when the database is on another server - specify the server address;
  • DB_DATABASE - database name;
  • DB_USER - the name of the user who works with the database;
  • DB_USER_PASSWORD - database user password;
  • DB_ROOT_PASSWORD - password of the root database user;
  • AWS_S3_URL - url of cloud backup storage;
  • AWS_S3_BUCKET - name of the bucket in the backup storage;
  • AWS_S3_ACCESS_KEY_ID - storage key;
  • AWS_S3_SECRET_ACCESS_KEY - storage password;
  • AWS_S3_LOCAL_MOUNT_POINT - path to the local folder where we mount the cloud storage;
  • MAIL_SMTP_HOST - smpt host for sending mail, e.g. smtp.gmail.com;
  • MAIL_SMTP_PORT - smpt port. Default 25;
  • MAIL_SMTP_USER - smpt username;
  • MAIL_SMTP_PASSWORD - smtp password.

Separately, it is worth mentioning COMPOSE_FILE. Depending on the environment we are launching a website - we need different services. For example, locally - you only need a base app, cloud for backups:

dc-app.yml:dc-cloud.yml

For dev server - all above and https:

dc-app.yml:dc-proxy.yml:dc-cloud.yml

For production server - app, https and cloud backups:

dc-app.yml:dc-proxy.yml:dc-cloud.yml

Also, you may need to open database ports on dev server (for example, for PhpStorm database inspect) and open 80 port for nginx. Ports setting up in compose-dev.yml, so in this case you need:

dc-app.yml:dc-dev.yml:dc-standalone.yml

4. Build images and up server

docker-compose build
docker-compose up -d

5. Initialize crontab

./cgi-bin/prepare-crontab.sh

6. Optional. Restore backups

./cgi-bin/restore-backup.sh

7. Optional. Install dependencies

docker-compose run --rm composer update
docker-compose run --rm composer install

P.S. You can add alias to make interaction with composer more simple:

vi ~/.bashrc

alias dcr='docker-compose run --rm'

And then use composer:

dcr composer install

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.