You’re not receiving notifications from this thread.
Docker Basics for Rails Discussion
If I run rails inside of Docker, does this set-up require more resources from my my machine?
Hey Chris, when I downloaded the Source Code GitHub repo and ran
docker-compose up, it couldn't build sqlite3.
I tried adding a dependency for sqlite-dev in the Dockerfile, then it worked.
I opened a corresponding PR in your repo to add the dependency.
Great episode! I already use Docker for local development and I love it. Are you planning to do an episode to explain how to deploy a dockerized rails application? It seems very obscure to me.
Thanks for the great tutorial! I am a beginner in dockerizing rails app and get started with this tutorial. I realized some optimization may have been omitted to keep the tutorial concise. Following are some optimization tricks I found useful if starting from the Dockerfile :)
Add (at least)
.dockerignorefile, so the
COPY . /app/step could skip these files. (This could save you a log of time/docker image size when .git is huge)
Avoid the error: 'A server is already running. Check /project/tmp/pids/server.pid. Exiting' with an
Refer to Docker docs - Sample applications - Rails and PostgreSQL for the complete script, and don't forget to change
#!/bin/shsince we are using Alpine in this tutorial.
Avoid needing to run
yarn installagain after change the source code and re-build image.
COPY . /app/ ENV BUNDLE_PATH /gems RUN yarn install RUN bundle install
ENV BUNDLE_PATH /gems COPY package.json yarn.lock /app/ RUN yarn install COPY Gemfile Gemfile.lock /app/ RUN bundle install # Steps above could be cached most of the time when re-building image # Copy source code after dependencies installed COPY . /app/
Would this prevent gems from being re-installed every time you build the image, even when you did not make any changes to Gemfile?
This is great, please more docker + rails tutorials. I would like to see how to not re-install all gems if you rebuild the image but have not changed the Gemfile at all.
I agree with Drazen. More Docker+Rails tutorials. Especially on how to deploy to production. Also, how to add sidekiq.
Second this! Probably needs to be tweaked but here's my
docker-compose.yml that currently works for local dev with sidekiq
services: postgres: image: postgres:10.4-alpine env_file: - ./env/common.env - ./env/dev.env ports: - 5432:5432 volumes: - postgres:/var/lib/postgresql/data redis: image: redis:4.0-alpine ports: - 6379:6379 volumes: - redis:/data app: &app_base build: context: . args: - BUNDLE_WITHOUT=production env_file: - ./env/common.env - ./env/dev.env command: bundle exec puma -C config/puma.rb ports: - 3000:3000 volumes: - .:/app depends_on: - postgres - redis stdin_open: true tty: true sidekiq: <<: *app_base command: bundle exec sidekiq -C config/sidekiq.yml ports:  stdin_open: false tty: false volumes: redis: postgres:
Note - in the docker file you can't have the last 2 lines of the tutorial triggering rails s
What if I have a windows computer and dont want to install ruby on the computer. Can I create a docker environment that has ruby and rails installed and where I do all the development, editing,
rails new inside the image. Even run vscode outside and ssh into the image. Is that possible, and do you have a pointer for an article of yours or elsewhere to help me set that up?
You can make docker-compose create the project for you if you already have defined a
Dockerfile and a
docker-compose run --no-deps web rails new . --force --database=postgresql
Hello, I am getting this error "Don't know how to build task 'bundle' (See the list of available tasks with
rails --tasks)" after running docker-compose run web bundle. Any idea why it is? Thanks