Docker/docker-compose enhancements
The following enhancements have been made to docker/docker-compose * Fixed bug when building the image. * docker-compose up starts the server * Scaffolding inside the container respect the ownership of the files outside it * Volumes are tagged as 'delegated' in order to improve performance for mac/windoze users. * bundler stores packages in a volume. This whay new packages can be added without rebuilding the image: ```bash docker-compose run app bundle install ```
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -33,3 +33,6 @@
|
||||
|
||||
public/sitemap.xml
|
||||
public/system/
|
||||
|
||||
# Ignore vim swap files
|
||||
*.swp
|
||||
|
||||
15
Dockerfile
15
Dockerfile
@@ -1,8 +1,17 @@
|
||||
# # Select ubuntu as the base image
|
||||
FROM coreapps/ruby2.3
|
||||
FROM ruby:2.3.6
|
||||
|
||||
# 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
|
||||
ENV RAILS_ROOT /var/www/consul
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# service configuration for our database
|
||||
database:
|
||||
version: '3'
|
||||
services:
|
||||
# service configuration for our database
|
||||
database:
|
||||
|
||||
# use the preferred version of the official Postgres image
|
||||
# see https://hub.docker.com/_/postgres/
|
||||
@@ -9,18 +11,21 @@ database:
|
||||
volumes:
|
||||
- docker-example-postgres:/var/lib/postgresql/data
|
||||
|
||||
# service configuration for our dockerized Rails app
|
||||
app:
|
||||
# service configuration for our dockerized Rails app
|
||||
app:
|
||||
|
||||
# use the Dockerfile next to this file
|
||||
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
|
||||
# environment:
|
||||
#RAILS_ENV: $RAILS_ENV
|
||||
|
||||
# makes the app container aware of the DB container
|
||||
links:
|
||||
depends_on:
|
||||
- database
|
||||
|
||||
# expose the port we configured Unicorn to bind to
|
||||
@@ -28,4 +33,8 @@ app:
|
||||
- "3000:3000"
|
||||
# map our application source code, in full, to the application root of our container
|
||||
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