Skip to content

Instantly share code, notes, and snippets.

@mankind
Last active January 2, 2019 12:35
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 mankind/fe4e09a9faab17438d74ff28f6130704 to your computer and use it in GitHub Desktop.
Save mankind/fe4e09a9faab17438d74ff28f6130704 to your computer and use it in GitHub Desktop.
example docker-compose with netwroks
# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
host: 172.19.0.2
port: <%= ENV['POSTGRES_PORT'] %>
username: wizebee
password: <%= ENV['POSTGRES_PASSWORD'] %>
development:
<<: *default
database: filter_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: filter
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: filter_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: filter_production
username: filter
password: <%= ENV['FILTER_DATABASE_PASSWORD'] %>
#https://812bits.wordpress.com/2016/03/23/postgresql-jsonb-type-hands-on/
#https://blog.andyet.com/2016/02/04/postgres-9.5-document-store-hybrid/
#http://www.dalibo.org/_media/understanding_explain.pdf
#https://github.com/fordodone/static_ip_docker/blob/master/docker-compose.yml
#https://fordodone.com/2016/03/30/docker-compose-static-ip-address-in-docker-compose-yml/
#--force-rm Always remove intermediate containers.
#docker-compose build --force-rm and then docker-compose up
#docker-compose --file docker-compose-dev.yml build --force-rm --verbose
# docker-compose --file docker-compose-dev.yml up redis
#https://docs.docker.com/compose/compose-file/#versioning
#https://github.com/tutumcloud/redis#setting-a-specific-password
#https://github.com/docker-library/docs/blob/master/redis/content.md#additionally-if-you-want-to-use-your-own-redisconf-
#COPY redis.conf /usr/local/etc/redis/redis.conf
#CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
#https://raw.githubusercontent.com/antirez/redis/2.8/redis.conf
#eg docker-compose version 2
#https://github.com/vsemionov/hippo/blob/master/docker-compose.yml
#https://github.com/Nanocloud/community/blob/master/modules/docker-compose.yml
#sudo cat /var/lib/docker/volumes/redis-conf/_data/redis.conf
version: '2'
services:
db:
image: postgres:latest #9.5.4
ports:
- "5432:5432"
networks:
mydev:
ipv4_address: 172.19.0.2
restart: always
environment:
#for use in rails datab
#DB_ENV_POSTGRES_PASSWORD="${POSTGRES_PASSWORD}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
#POSTGRES_DB
#command: postgres -c max_connections=100 -c tcp_keepalives_idle=30 -c tcp_keepalives_interval=10 -c tcp_keepalives_count=3
volumes:
- postgres_data:/var/lib/postgresql/data
container_name: "postgres"
redis:
image: redis:latest #3.2.3
mem_limit: 268435456
environment:
- REDIS_PASS="${REDIS_PASS}"
ports:
- "6379:6379"
networks:
mydev:
ipv4_address: 172.19.0.3
command: redis-server --requirepass "${REDIS_PASS}" --appendonly yes
#command: redis-server --requirepass "${REDIS_PASS}" --maxclients 10000 --tcp-keepalive 30 --appendonly yes
restart: always
volumes:
- redis_data:/data
#- redis-conf/_data/redis.conf:/usr/local/etc/redis/redis.conf:ro
#- redis-conf:/usr/local/etc/redis/redis.conf:ro
container_name: "redis"
volumes:
postgres_data:
driver: local
redis_data:
driver: local
#redis-conf:
#driver: local
networks:
mydev:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/24
gateway: 172.19.0.1
#https://github.com/mperham/sidekiq/wiki/Using-Redis
=begin
Sidekiq.configure_server do |config|
config.redis = { url: "redis://#{Rails.application.secrets.redis_host}:#{Rails.application.secrets.redis_host_port}", password: "#{Rails.application.secrets.redis_password
}", namespace: Rails.applications.secrets.redis_namespace }
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://#{Rails.application.secrets.redis_host}:#{Rails.application.secrets.redis_host_port}", password: "#{Rails.application.secrets.redis_password
}" }
end
=end
if Rails.env == 'development'
Sidekiq.configure_server do |config|
#config.redis = { url: "redis://172.19.0.2:6379", password: ""}
#config.redis = { url: "redis://:password@172.19.0.2:6379"}
config.redis = {:url => Rails.application.secrets["redis_local_url"]}
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://:password@172.19.0.2:6379" }
config.redis = {:url => Rails.application.secrets["redis_local_url"]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment