Docker Compose
For others, [as well as comments on how to do it better]
To setup with Docker compose I did the following.
1. Created a project directory and added it to git
2. Cloned into project/rails subdirectory
3. created docker-compose.yml in root
4. copied Docker file into root from rails directory.
Issues
1. tzdata needs to be installed on alpine
2. Added check files to yarn install. Didn't help so disabled check
in config/development.rb
config.webpacker.check_yarn_integrity = false
Dockerfile edits
To setup with Docker compose I did the following.
1. Created a project directory and added it to git
2. Cloned into project/rails subdirectory
3. created docker-compose.yml in root
4. copied Docker file into root from rails directory.
Issues
1. tzdata needs to be installed on alpine
2. Added check files to yarn install. Didn't help so disabled check
in config/development.rb
config.webpacker.check_yarn_integrity = false
Dockerfile edits
FROM ruby:2.6.3-alpine RUN apk add --update --virtual \ runtime-deps \ postgresql-client \ build-base \ libxml2-dev \ libxslt-dev \ nodejs \ yarn \ libffi-dev \ readline \ build-base \ postgresql-dev \ libc-dev \ linux-headers \ readline-dev \ file \ imagemagick \ git \ tzdata \ && rm -rf /var/cache/apk/* WORKDIR /app ADD rails/. /app/ ENV BUNDLE_PATH /gems RUN yarn install --check-files RUN bundle install ENTRYPOINT ["bin/rails"] CMD ["s", "-b", "0.0.0.0"] EXPOSE 3000
docker-compose.yml
version: "2.4" services: web: build: . volumes: - ./rails:/app working_dir: /app ports: - 3000:3000 depends_on: - db environment: DATABASE_URL: postgres://postgres@db db: image: mdillon/postgis:11 ports: - 5432:5432
modifying the gems becomes a pain real quick.
Here is a much better method thanks to
https://anonoz.github.io/tech/2019/03/10/rails-docker-compose-yml.html
Dockerfile.dev
Here is a much better method thanks to
https://anonoz.github.io/tech/2019/03/10/rails-docker-compose-yml.html
Dockerfile.dev
FROM ruby:2.6.3-alpine RUN apk add --update --virtual \ runtime-deps \ postgresql-client \ build-base \ libxml2-dev \ libxslt-dev \ nodejs \ yarn \ libffi-dev \ readline \ build-base \ postgresql-dev \ libc-dev \ linux-headers \ readline-dev \ file \ imagemagick \ git \ tzdata \ && rm -rf /var/cache/apk/* WORKDIR /app ADD rails/. /app/ ENV BUNDLE_PATH /gems EXPOSE 3000 CMD ["bundle","yarn", "exec", "rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
version: "3.0" services: web: build: context: . dockerfile: Dockerfile.dev volumes: - ./rails:/app - ./bundler_gems:/gems working_dir: /app ports: - 3000:3000 depends_on: - db environment: DATABASE_URL: postgres://postgres@db command: bundle exec rails s -p 3000 -b '0.0.0.0' db: image: mdillon/postgis:11 ports: - 5432:5432 volumes: - ./postgres:/var/lib/postgresql/data pgadmin4: image: thajeztah/pgadmin4 ports: - 5050:5050 depends_on: - db volumes: postgres: bundler_gems:
run
docker-compose build docker-compose run --rm web bundle install -j8 docker-compose run --rm web yarn install -j8
This is so much quicker not needing to build the base image each time
Hey
Chris Oliver
,
The build works fine. But, executing the next step errors.
The build works fine. But, executing the next step errors.
docker-compose run --rm web bundle install -j8 Starting api_redis_1 ... done Starting api_db_1 ... done Could not find rake-13.0.1 in any of the sources Run `bundle install` to install missing gems.
I've added to the Dockerfile and installation of rake in case it's missing. But, that doesn't seem to do it. This is the current Dockerfile.
FROM ruby:2.7.0-alpine RUN apk add --update --virtual \ runtime-deps \ postgresql-client \ build-base \ libxml2-dev \ libxslt-dev \ nodejs \ yarn \ libffi-dev \ readline \ build-base \ postgresql-dev \ libc-dev \ linux-headers \ readline-dev \ file \ imagemagick \ git \ && rm -rf /var/cache/apk/* WORKDIR /app COPY . /app/ ENV BUNDLE_PATH /gems ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \ BUNDLE_BIN=$BUNDLE_PATH/bin ENV PATH /app/bin:$BUNDLE_BIN:$PATH RUN gem update --system && \ gem install bundler && \ gem install rake RUN yarn install RUN bundle install ENTRYPOINT ["bin/rails"] CMD ["s", "-b", "0.0.0.0"] EXPOSE 3000
And, here's the docker-compose.
version: "3.0" services: web: build: context: . dockerfile: Dockerfile volumes: - .:/app - ./bundler_gems:/gems working_dir: /app ports: - 3000:3000 depends_on: - db - redis environment: DATABASE_URL: postgres://postgres@db command: bundle exec rails s -p 3000 -b '0.0.0.0' db: image: mdillon/postgis:11 ports: - 5432:5432 volumes: - ./postgres:/var/lib/postgresql/data redis: image: redis:5-alpine volumes: - ./redis:/data ports: - 6379 pgadmin4: image: thajeztah/pgadmin4 ports: - 5050:5050 depends_on: - db volumes: postgres: bundler_gems:
William,
Here are my current files
which I run with a plain docker-compose up
Hope these help
Dockerfile
Here are my current files
which I run with a plain docker-compose up
Hope these help
Dockerfile
FROM ruby:2.6.3-alpine RUN echo \ # replacing default repositories with edge ones && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" > /etc/apk/repositories \ && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ && echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories RUN apk add --update --virtual \ runtime-deps \ postgresql-client \ build-base \ libxml2-dev \ libxslt-dev \ nodejs \ yarn \ libffi-dev \ readline \ build-base \ postgresql-dev \ libc-dev \ linux-headers \ file \ imagemagick \ git \ tzdata \ gdal \ geos \ geos-dev \ && rm -rf /var/cache/apk/* WORKDIR /app ADD rails/. /app/ ENV BUNDLE_PATH /gems #RUN bundle install #RUN yarn install --check-files EXPOSE 3000 CMD ["bundle","yarn", "exec", "rails", "server", "-b", "0.0.0.0"]
Docker-compose
version: "2.4" services: web: build: . volumes: - ./rails:/app - ./bundler_gems:/gems working_dir: /app command: bundle exec rails s -p 3000 -b '0.0.0.0' ports: - 3000:3000 depends_on: - db - redis_db - elasticsearch links: - redis_db - elasticsearch environment: DATABASE_URL: postgis://postgres@db ELASTICSEARCH_URL: http://elasticsearch:9200 RECAPTCHA_SITE_KEY: xxxxxx RECAPTCHA_SECRET_KEY: xxxxx airflow: image: puckel/docker-airflow volumes: - ./airflow:/usr/local/airflow ports: - 8081:8080 - 5555:5555 command: webserver environment: DATABASE_URL: postgres://postgres@db depends_on: - db - rabbitmq pgadmin4: image: thajeztah/pgadmin4 ports: - 5050:5050 depends_on: - db links: - stellar rabbitmq: image: rabbitmq:3-management ports: - "15672:15672" - "5672:5672" labels: NAME: "rabbitmq" volumes: #- "./enabled_plugins:/etc/rabbitmq/enabled_plugins" - ./rabbitmq-isolated.conf:/etc/rabbitmq/rabbitmq.config depends_on: - db db: image: mdillon/postgis:11 ports: - 5432:5432 redis_db: image: redis elasticsearch: image: elasticsearch:7.1.1 ports: - 9200:9200 - 9300:9300 mem_limit: 4g environment: - discovery.type=single-node - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: bundler_gems:
Thanks.. I'll try with these.
If this doesn't work out, I'll post my version. I have one that's Ubuntu-base I'm pretty sure I can adapt.. it has the advantage/disadvantage that it's configurable, in that you can set ruby version, bundler version, etc. in the docker-compose.yml file.
If this doesn't work out, I'll post my version. I have one that's Ubuntu-base I'm pretty sure I can adapt.. it has the advantage/disadvantage that it's configurable, in that you can set ruby version, bundler version, etc. in the docker-compose.yml file.
I managed to get this working with the following example:
https://jumpstartrails.com/discussions/252#1450
https://jumpstartrails.com/discussions/252#1450
Notifications
You’re not receiving notifications from this thread.