DockerizeRails

Installation

Add this line to your rails application's Gemfile:

gem 'dockerize_rails'

And then execute: bash $ bundle

Usage

First create the configuration file .dockerize.yml for the gem itself. Run: bundle exec dock configure to generate the template. Use --tiny option to skip the description of configuration fields: bundle exec dock configure --tiny.

To create the docker config files (Dockerfile, provisions, docker-compose.yml etc.) run: bundle exec dock dockerize. To create docker environment for running tests use --test-env option: bundle exec dock dockerize --test-env.

Use docker-compose to run application in docker: docker-compose build && docker-compose up -d.

If you see migration error in browser run the following commands:

$ docker-compose down        # stop and destroy all running containers
$ docker-compose up -d mysql # if application uses postgresql database use 'postgresql' instead of 'mysql'
$ sleep 30                   # wait 30 seconds to let the database container start properly
$ docker-compose up -d rails # now start the rails container

To remove docker configurations: bundle exec dock undockerize. Use --purge option to remove .dockerize.yml file: bundle exec dock undockerize --purge

All available commands: bash $ bundle exec dock help $ bundle exec dock configure $ bundle exec dock configure --tiny $ bundle exec dock dockerize $ bundle exec dock dockerize --test-env $ bundle exec dock undockerize $ bundle exec dock undockerize --purge $ bundle exec dock docker_info $ bundle exec dock docker_pull $ bundle exec dock docker_build $ bundle exec dock docker_build --log $ bundle exec dock docker_build --rebuild $ bundle exec dock docker_build --rebuild --force $ bundle exec dock docker_start $ bundle exec dock docker_stop $ bundle exec dock docker_stop --delete $ bundle exec dock docker_delete

Help message: “` Usage: dock <command> or: bundle exec dock <command>

commands:

    configure, c, rc, cr           - Generates '.dockerize.yml'
      [--tiny]        -- Generates shorter config file, skipping all descriptions

    dockerize, dc, d               - Generates docker config files
      [--test-env]    -- Generates configurations to run tests.

    undockerize, ud, du, u, dd     - Removes docker configurations
      [--purge]       -- Also removes .dockerize.yml

    docker_info, info              - Shows Docker information
    docker_pull, pull              - Pulls base Docker images (ruby, mysql/postgres)
    docker_build, build            - Builds Docker images
      [--log]         -- Displays/Streams build log
      [--rebuild]     -- Deletes images if exists and rebuilds
      [--force]       -- Force Image deletion. Works only with --rebuild option

    docker_start, start            - Run/Starts Docker containers
    docker_stop, stop              - Stops Docker containers
      [--delete]      -- Also deletes the containers

    docker_delete, delete          - Deletes Docker containers
    help, h                        - Prints this message

“`

Demo

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at github.com/eendroroy/dockerize_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.