Skip to content

Instantly share code, notes, and snippets.

@Electron-libre
Last active March 28, 2018 17:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Electron-libre/2392fddb74150992ea514580428022c2 to your computer and use it in GitHub Desktop.
Save Electron-libre/2392fddb74150992ea514580428022c2 to your computer and use it in GitHub Desktop.

Running long jobs on remote machine with docker-machine

Use the -d flag with run command.

EG:

eval $(docker-machine env feature)
docker-compose -f delivery.docker-compose.yml run -d rails rake db:seed

Clean Up weekly or die

Take care of you disk space.

docker system prune

Managing Gems

For each change in Gemfile you have to :

docker-compose build myapp

This will ensure that the gem versions within you Image and containers will be updated according to gemfile

docker-compose run --no-deps myapp bundle install

This will ensure that the Gemfile.lock from your local filesystem will be updated according to Gemfile.

Overriding docker compose

( Require docker-compose >= 1.5 )

Do not edit the docker-compose.yml. Create a docker-compose.override.yml file and place your setup within. ( and please do not commit this file )

See https://docs.docker.com/compose/extends/

Load existing DB within a mysql container

Within your docker-compose.override.yml mount the source sql file within the container entry point.

Eg:

pctdb:
  volumes:
    - ../db_pct_20151228.sql:/docker-entrypoint-initdb.d/init.sql

See https://hub.docker.com/_/mysql/

Using local sources for a gem

Then within your docker-compose.override.yml mount the volume container and configure bundler to use the mounted sources.

EG:

app:
  environment:    
    BUNDLE_LOCAL__GEM_NAME: /gem_name
  volumes_from:
    - gem_name
    
volumes:
  gem_name:
    driver_opts:
        type: none
        device: /absolute/path/on/your/system/for/gem_name
        o: bind


Using custom gems within your dev environment

Let say for any reason that you want to add a dependency your development environment ( like a custom debugger or profiler … )

First ensure your Gemfile contain something like this:

local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
  eval_gemfile local_gemfile
end

Then add the gem to the Gemfile.local file

gem 'rmagick'

Then create a Dockerfile.local

FROM foo/develop/etm

apt-get update && apt-get install libimagemagick


ADD Gemfile
ADD Gemfile.lock
ADD Gemfile.local

RUN bundle install

Then in your docker-compose.override.yml

rails:
  dockerfile: Dockerfile.local

OH My ZSH machine prompt

Within your .zshrc at the end or in a sourced library file add

 docker_machine_set () {
  eval $(docker-machine env $@)
  export RPROMPT='%{$fg[red]%}${DOCKER_MACHINE_NAME}%{$reset_color%}'
}

alias dms=docker_machine_set

to get the current machine name in the prompt use the alias or function to set the machine EG:

dms staging.synbioz.com 

client is newer than server ( Docker complains about api version )

You can set the client api version through env var DOCKER_API_VERSION

EG:

DOCKER_API_VERSION=1.22

Logrotate for containers

Add a logrotate conf to the system with the following :

# /etc/logrotate.d/docker-container

/var/lib/docker/containers/*/*.log {
  rotate 7
  daily
  compress
  size=1M
  missingok
  delaycompress
  copytruncate
}

Faster bundle install

Within your dockerfile:

# Allow to install gem in parallel
ENV BUNDLE_JOBS 3

Do not forget .gemrc for light and fast gem install

Within docker file

# Configure ruby gem ( see .gemrc for options )
ADD .gemrc /root/

At the root of the context within .gemrc

---
:update_sources: true
:benchmark: false
:backtrace: true
:verbose: true
gem: --no-ri --no-rdoc
install: --no-rdoc --no-ri
update:  --no-rdoc --no-ri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment