Skip to content

Instantly share code, notes, and snippets.

@palkan
Last active October 18, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palkan/a009c23915e2ea663cc0ba3fac69c7be to your computer and use it in GitHub Desktop.
Save palkan/a009c23915e2ea663cc0ba3fac69c7be to your computer and use it in GitHub Desktop.
rde: reusable docker environment

RDE: reusable docker environment

This tools is a wrapper over docker-compose.yml, which allows you to re-use common configuration between projects without copying docker-compose and Dockerfile files.

It's meant to be used for libraries development.

Installation

  • Install Docker and docker-compose first

  • brew install rde

  • rde init—generates pre-built configuraion inside RDE_HOME directory (defaults to ~/.rde) (optional: generated the first time you use RDE)

Usage

Running bash withing a specific environment

You can open bash session within a specific environment (executor) with current directory mounted under /app without any configuration:

$ rde -e ruby
root@1123:/app#

Alternatively you can run a command within a specific envrironment:

$ rde run -e jruby -- ruby script.rb

Using with .rde.yml

You can preconfigure the default executor by adding the .rde.yml into the project's root directory:

# main executor name (or full configuration)
executor: ruby
# additional environment variables (merged with the original)
environment:
  - DATABASE_URL=postgres://postgres@postgres:5432/docker
# expose ports
ports:
  - 3000:3000
# list of other executors (e.g., databases)
depends_on:
  - executor: postgres

Now you can launch the env by simply running rde from the project's root directory:

$ rde
root@1123:/app#

// equals to
$ rde -e ruby --env="DATABASE_URL=postgres://postgres@postgres:5432/docker" -d postgres

// run with --service-ports
$ rde --ports -- rackup -p 3000

Aliases

You can add aliases to avoid typing the same options all the time:

rde alias jruby='run -e jruby -- ruby'

rde jruby script.rb

Aliases are stored in ~/.rde/aliases, you can edit them manually:

jruby='run -e jruby -- ruby'

How it works?

RDE generates virtual docker-compose.yml file every time you run a command by glueing executors configuration and your local configuration if any.

Volumes, networks, images—everything is reused between the projects.

That's it!

Resources:

# ~/.rde/config.yml
executors:
- name: ruby
service:
image: ruby:2.6.3
environment:
- BUNDLE_PATH=/bundle
- BUNDLE_CONFIG=/app/.bundle/config
- HISTFILE=/bundle/.bash_history
- LANG=C.UTF-8
command: bash
working_dir: /app
tmpfs:
- /tmp
volumes:
- ${CURRENT_DIR}:/app:cached
- ruby_bundler:/bundle
- ${RDE_HOME}/shared/.bashrc:/root/.bashrc:ro
- ${RDE_HOME}/ruby/.irbrc:/root/.irbrc:ro
- ${RDE_HOME}/ruby/.pryrc:/root/.pryrc:ro
volumes:
ruby_bundler:
- name: postgres
service:
image: postgres:10
environment:
- POSTGRES_DB=docker
volumes:
- ${RDE_HOME}/postgres/.psqlrc:/root/.psqlrc:ro
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
- name: redis
service:
image: redis:3.2-alpine
ports:
- "6379:6379"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment