This is a demo Rails app with Docker. It creates development environment and scripts for deployment to production.
This repository is based on https://github.com/whitesmith/rails-pg-fig-sample.
- Install Docker and Fig.
- Run
./scripts/init_development.sh
to create development environment. - Run
fig up
to start rails web server. - Open
http://localhost:3000/
in the web browser. On Mac OS, runboot2docker ip
command to get the IP address.
fig stop
- stops the app.
fig rm
- removes the app containers.
It creates a docker image for the Rails app called web
.
It is configured to keep the source code on developer host and not in the image.
It allows to make changes to the source code and see results in the browser.
Following docker containers are created:
- Web for Rails app.
- DB for Postgres DB server.
- iipersist-db-data is a Data Volume Container for the database storage.
- iipersist-gems-2.1 is another Data Volume Container for the gems.
./scripts/docker_create_deploy_image.sh myaccount/image
Use your Docker Hub account name and deployment image name. The single purpose of this step is to create a production image that contains app's source code. You may want to make this repository private.
docker push myaccount/image
- In
fig_production.yml
replacemyaccount/image
with the image name you specified in step 1. - Copy
fig_production.yml
tofig.yml
to your production host. - Use
docker_upload_data_volume_container.sh
script to upload database files and Gems to your server:
./scripts/docker_upload_data_volume_container.sh iipersist-gems-2.1 /usr/local/bundle myserver.com
./scripts/docker_upload_data_volume_container.sh iipersist-db-data /var/lib/postgresql/data myserver.com
Here replace myserver.com
with your production server name.
Finally, run fig up
on your production host to create production environment and launch the app.
Scripts are located in scripts
directory.
Cleanup script that removes containers for the app. It does not remove the database and gems containers.
This script can be run after fig stop
and fig rm
.
Backup data from data volume container into a tar.gz file in the current directory.
Usage:
docker_data_volume_container_backup.sh CONTAINER_NAME VOLUME_PATH
Example:
./docker_data_volume_container_backup.sh iipersist-db-data /var/lib/postgresql/data
Restore data from CONTAINER_NAME.tar.gz into a data volume container.
Usage:
docker_data_volume_container_backup.sh CONTAINER_NAME VOLUME_PATH
Example:
Restore iipersist-db-data.tar.gz into iipersist-db-data Data Volume Container:
./docker_data_volume_container_restore.sh iipersist-db-data /var/lib/postgresql/data
This script uploads data volume container to a remote host.
The job includes the following steps:
- It archives a local data volume container.
- Copies the archive to remote host.
- Restores the archive into the data volume container on remote host.
Usage:
docker_upload_data_volume_container.sh CONTAINER_NAME VOLUME_PATH HOST_SSH_ADDRESS
Example:
Uploads iipersist-db-data Data Volume Container to myserver.com host.
./docker_upload_data_volume_container.sh iipersist-db-data /var/lib/postgresql/data myserver.com
Resources that helped me with this project:
Feel free to create an issue ticket. Or if you are stuck and need help please do not hesitate to ask.