full stack nginx Rails for everyone with docker compose
If You want to build a website with Rails at short time;
Full stack Nginx Rails:
Plus, manage docker containers with Portainer.
With this project you can quickly run the following:
For certbot (letsencrypt) certificate:
IPv4/IPv6 Firewall
Create rules to open ports to the internet, or to a specific IPv4 address or range.
- http: 80
- https: 443
- portainer: 9001
- phpmyadmin: 9090
Contents:
- Auto Configuration and Installation
- Requirements
- Manual Configuration and Installation
- Portainer Installation
- Usage
Automatic
Exec install shell script for auto installation and configuration
download with
git clone https://github.com/damalis/full-stack-nginx-rails-for-everyone-with-docker-compose.git
Open a terminal and cd
to the folder in which docker-compose.yml
is saved and run:
cd full-stack-nginx-rails-for-everyone-with-docker-compose
chmod +x install.sh
./install.sh
Requirements
Make sure you have the latest versions of Docker and Docker Compose installed on your machine.
Clone this repository or copy the files from this repository into a new folder. In the docker-compose.yml file you may change the database from MariaDB to MySQL.
Make sure to add your user to the docker
group.
Manual
Configuration
download with
git clone https://github.com/damalis/full-stack-nginx-rails-for-everyone-with-docker-compose.git
Open a terminal and cd
to the folder in which docker-compose.yml
is saved and run:
cd full-stack-nginx-rails-for-everyone-with-docker-compose
Copy the example environment into .env
cp env.example .env
Edit the .env
file to change values of LOCAL_TIMEZONE
, DOMAIN_NAME
, DIRECTORY_PATH
, LETSENCRYPT_EMAIL
, DB_USER
, DB_PASSWORD
, DB_NAME
, MYSQL_ROOT_PASSWORD
, PMA_CONTROLUSER
, PMA_CONTROLPASS
, PMA_HTPASSWD_USERNAME
and PMA_HTPASSWD_PASSWORD
.
LOCAL_TIMEZONE=to see local timezones
DIRECTORY_PATH=pwd
at command line
and
cp ./phpmyadmin/apache2/sites-available/default-ssl.sample.conf ./phpmyadmin/apache2/sites-available/default-ssl.conf
change example.com to your domain name in ./phpmyadmin/apache2/sites-available/default-ssl.conf
file.
Installation
Firstly: will create external volume
docker volume create --driver local --opt type=none --opt device=${DIRECTORY_PATH}/certbot --opt o=bind certbot-etc
docker compose up -d
then reloading for webserver ssl configuration
docker container restart webserver
The containers are now built and running. You should be able to access the Rails installation with the configured IP in the browser address. https://example.com
.
For convenience you may add a new entry into your hosts file.
Portainer
docker compose -f portainer-docker-compose.yml -p portainer up -d
manage docker with Portainer is the definitive container management tool for Docker, Docker Swarm with it's highly intuitive GUI and API.
You can also visit https://example.com:9001
to access portainer after starting the containers.
Usage
You could manage docker containers without command line with portainer.
Show both running and stopped containers
The docker ps command only shows running containers by default. To see all containers, use the -a (or --all) flag:
docker ps -a
Starting containers
You can start the containers with the up
command in daemon mode (by adding -d
as an argument) or by using the start
command:
docker compose start
Stopping containers
docker compose stop
Removing containers
To stop and remove all the containers use the down
command:
docker compose down
to remove portainer and the other containers
docker rm -f $(docker ps -a -q)
Use -v
if you need to remove the database volume which is used to persist the database:
docker compose down -v
to remove external certbot-etc and portainer and the other volumes
docker volume rm $(docker volume ls -q)
to remove portainer and the other images
docker rmi $(docker image ls -q)
Project from existing source
Copy all files into a new directory:
You can now use the up
command:
docker compose up -d
Docker run reference
https://docs.docker.com/engine/reference/run/
Website
You should see the "Rails version: ... and Ruby version: ..." page in your browser. If not, please check if your installation satisfies Rails's requirements.
Blocked host: must add the contents of ./rails/config/environments/development.rb
with the following:
config.hosts << "example.com"
then docker container restart rails
https://example.com
add and/or remove rails site folders and files with any ftp client program in ./rails
folder.
You can also visit https://example.com
to access website after starting the containers.
Webserver
add or remove code in the ./webserver/templates/nginx.conf.template
file for custom nginx configurations
https://www.nginx.com/resources/wiki/start/topics/examples/simplerubyfcgi/
Database
Replace the contents of ./rails/config/database.yml
with the following:
default: &default
adapter: mysql2
host: database
username: ${DB_USER}
password: ${DB_PASSWORD}
pool: 5
development:
<<: *default
database: ${DB_NAME}
test:
<<: *default
database: myapp_test
https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
https://mariadb.com/kb/en/configuring-mariadb-with-option-files/
Redis
add the configuration in the relevant ./rails/config/environments/*.rb
file:
config.cache_store = :redis_cache_store, { url: 'redis' }
https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-rediscachestore
phpMyAdmin
You can add your own custom config.inc.php settings (such as Configuration Storage setup) by creating a file named config.user.inc.php with the various user defined settings in it, and then linking it into the container using:
./phpmyadmin/config.user.inc.php
You can also visit https://example.com:9090
to access phpMyAdmin after starting the containers.
The first authorize screen(htpasswd;username or password) and phpmyadmin login screen the username and the password is the same as supplied in the .env
file.
backup
This will back up the all files and folders in database/dump sql and html volumes, once per day, and write it to ./backups with a filename like backup-2023-01-01T10-18-00.tar.gz
can run on a custom cron schedule
BACKUP_CRON_EXPRESSION: '20 01 * * *'
the UTC timezone.