Merge pull request #2661 from jsperezg/docker-enhancements
Docker/docker-compose enhancements
This commit is contained in:
15
Dockerfile
15
Dockerfile
@@ -1,8 +1,17 @@
|
|||||||
# # Select ubuntu as the base image
|
FROM ruby:2.3.6
|
||||||
FROM coreapps/ruby2.3
|
|
||||||
|
|
||||||
# Install essential Linux packages
|
# Install essential Linux packages
|
||||||
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql-client nodejs imagemagick
|
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql-client nodejs imagemagick sudo
|
||||||
|
|
||||||
|
# Files created inside the container repect the ownership
|
||||||
|
RUN adduser --shell /bin/bash --disabled-password --gecos "" consul \
|
||||||
|
&& adduser consul sudo \
|
||||||
|
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||||
|
|
||||||
|
RUN echo 'Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bundle/bin"' > /etc/sudoers.d/secure_path
|
||||||
|
RUN chmod 0440 /etc/sudoers.d/secure_path
|
||||||
|
|
||||||
|
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
# Define where our application will live inside the image
|
# Define where our application will live inside the image
|
||||||
ENV RAILS_ROOT /var/www/consul
|
ENV RAILS_ROOT /var/www/consul
|
||||||
|
|||||||
@@ -1,31 +1,40 @@
|
|||||||
# service configuration for our database
|
version: '3'
|
||||||
database:
|
services:
|
||||||
|
# service configuration for our database
|
||||||
|
database:
|
||||||
|
|
||||||
# use the preferred version of the official Postgres image
|
# use the preferred version of the official Postgres image
|
||||||
# see https://hub.docker.com/_/postgres/
|
# see https://hub.docker.com/_/postgres/
|
||||||
image: postgres:9.4.5
|
image: postgres:9.4.5
|
||||||
|
|
||||||
# persist the database between containers by storing it in a volume
|
# persist the database between containers by storing it in a volume
|
||||||
volumes:
|
volumes:
|
||||||
- docker-example-postgres:/var/lib/postgresql/data
|
- docker-example-postgres:/var/lib/postgresql/data
|
||||||
|
|
||||||
# service configuration for our dockerized Rails app
|
# service configuration for our dockerized Rails app
|
||||||
app:
|
app:
|
||||||
|
|
||||||
# use the Dockerfile next to this file
|
# use the Dockerfile next to this file
|
||||||
build: .
|
build: .
|
||||||
|
entrypoint: /usr/local/bin/entrypoint.sh
|
||||||
|
command: bundle exec rails s -p 3000 -b '0.0.0.0'
|
||||||
|
working_dir: /var/www/consul
|
||||||
|
|
||||||
# rely on the RAILS_ENV value of the host machine
|
# rely on the RAILS_ENV value of the host machine
|
||||||
# environment:
|
# environment:
|
||||||
#RAILS_ENV: $RAILS_ENV
|
#RAILS_ENV: $RAILS_ENV
|
||||||
|
|
||||||
# makes the app container aware of the DB container
|
# makes the app container aware of the DB container
|
||||||
links:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
|
|
||||||
# expose the port we configured Unicorn to bind to
|
# expose the port we configured Unicorn to bind to
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
# map our application source code, in full, to the application root of our container
|
# map our application source code, in full, to the application root of our container
|
||||||
volumes:
|
volumes:
|
||||||
- .:/var/www/consul
|
- .:/var/www/consul:delegated
|
||||||
|
- bundle:/usr/local/bundle:delegated
|
||||||
|
volumes:
|
||||||
|
docker-example-postgres: {}
|
||||||
|
bundle: {}
|
||||||
|
|||||||
17
scripts/entrypoint.sh
Executable file
17
scripts/entrypoint.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh -x
|
||||||
|
|
||||||
|
USER_UID=$(stat -c %u /var/www/consul/Gemfile)
|
||||||
|
USER_GID=$(stat -c %g /var/www/consul/Gemfile)
|
||||||
|
|
||||||
|
export USER_UID
|
||||||
|
export USER_GID
|
||||||
|
|
||||||
|
usermod -u "$USER_UID" consul 2> /dev/null
|
||||||
|
groupmod -g "$USER_GID" consul 2> /dev/null
|
||||||
|
usermod -g "$USER_GID" consul 2> /dev/null
|
||||||
|
|
||||||
|
chown -R -h "$USER_UID" "$BUNDLE_PATH"
|
||||||
|
chgrp -R -h "$USER_GID" "$BUNDLE_PATH"
|
||||||
|
|
||||||
|
/usr/bin/sudo -EH -u consul "$@"
|
||||||
|
|
||||||
Reference in New Issue
Block a user