Episodes
partydrone PRO said 11 months ago on Docker on Rails 7 :
`WORKDIR /app` both (1) creates the directory if it doesn't exist and (2) sets it as the current working directory for all subsequent commands in the Dockerfile. For this reason, `RUN mkdir /app` is not necessary. 😉

partydrone PRO said 11 months ago on Docker on Rails 7 :
If the only reason for having the `base` service is to share configuration, I believe a best practice is to create a custom root-level definition beginning with `x-` and using that.

Also worth noting is the difference between "mapping" ports vs "exposing" ports in a Compose file. When mapping a port (e.g., `- 3000:3000` for the Rails app), you are mapping the port on your local machine to a port on the container. If you only expose a port (e.g., `- 5432` for the database service), Compose maps a random port on your machine to the port on the container. To determine what that random port is, you can run `docker compose ps`.

In the end, your docker-compose.yml file could look like this:

version: "3.8"

x-app: &app
  build:
    args:
      RUBY_VERSION: "3.0.2-apline"
    context: .
    dockerfile: Dockerfile.dev
  depends_on:
    - db
    - redis
  environment:
    - DATABASE_URL=postgres://postgres:[email protected]:5432
  stdin_open: true
  tty: true
  volumes:
    - .:/app:cached
    - bundle:/usr/local/bundle
    - node_modules:/app/node_modules

services:
  db:
    environment:
      - POSTGRES_PASSWORD=postgres
    image: postgresql:14-alpine
    ports:
      - 5432
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data

  redis:
    image: redis:alpine
    restart: always
  
  web:
    <<: *app
    command: rails s -b 0.0.0.0
    ports:
      - 3000:3000

  css:
    <<: *app
    command: yarn build:css --watch

  js:
    <<: *app
    command: yarn build --watch

volumes:
  bundle:
  node_modules:
  postgres:

partydrone PRO said 11 months ago on Docker on Rails 7 :
 , I am very interested to know how larger Rails apps perform when developing with Docker Compose on an M1 Mac. Historically, Rails app performance is abysmal when the app gets larger. With several large apps I worked with in a Docker environment on Intel Macs, it often takes 30 seconds or more for pages to load in a browser. The culprit has to do with volume mapping from macOS into a Docker container (see https://github.com/docker/roadmap/issues/7). I tried using docker-sync in the past, and more recently Mutagen, but I'm anxious to see how the M1 Macs perform.

David Kimura PRO said 11 months ago on Docker on Rails 7 :
Great tips   Thanks for sharing those.

I think that some have complained about Docker being slow even on the M1, but I never noticed those kinds of issues with taking 30 seconds or more for pages to load. I've never had to use Mutagen to get things synchronizing quickly. Maybe I'll give the gitlab oss repo a shot one day and see. I believe they have a docker config for development.

murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
Hi,

After installing the docker on my linux, the docker compose give me an error like:

 ⠿ Container rails7-postgres-1  Running                                                                                   0.0s
 ⠿ Container rails7-redis-1     Running                                                                                   0.0s
Could not find nokogiri-1.12.5, mini_portile2-2.6.1 in any of the sources
Run `bundle install` to install missing gems.

Then, i try to run 
docker compose run --rm app bin/rails bundle install

But it is still same. how can i solve the problem?

Regards,

Murat Üstüntaş

David Kimura PRO said 11 months ago on Docker on Rails 7 :
  What does your Dockerfile look like? My guess is that the bundle volume mount isn't in the proper spot. I would notice this problem when I was either referencing an incorrect directory for this volume mount.

murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
Hi,
I could not change the Dockerfile.dev. It is as in the source file. 

ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION

RUN apk add --no-cache --update build-base \
  bash \
  git \
  postgresql-dev \
  nodejs \
  yarn \
  imagemagick \
  vips \
  tzdata \
  && rm -rf /var/cache/apk/*

RUN mkdir -p /app
WORKDIR /app

COPY Gemfile Gemfile.lock ./
COPY package.json yarn.lock ./

RUN gem update --system
RUN bundle install -j $(nproc)
RUN yarn install

David Kimura PRO said 11 months ago on Docker on Rails 7 :
Ok, and the docker-compose looks the same far as the volume stuff goes?


murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
After downloading your source file, I ran it without making any changes, following all your commands. Sorry I encountered this error. I didn't make any changes on the Dockerfile and docker-compose.yml. The volumes still same as in the docker-compose.yml

volumes:
  bundle:
  node_modules:
  postgres:

Also, my docker version is Docker version 20.10.9, build c2ea9bc90b





David Kimura PRO said 11 months ago on Docker on Rails 7 :
Try docker compose up --build to see if rebuilding the images help. There could have been some weird issue with the file sync. Is this your first time trying docker   or have you been using it for some time?

murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
I ran the command as you said. Sorry, the nokogiri error still persists.My other docker services are also running. However, I am using the source file from you for the first time.

yarn run v1.22.10
$ esbuild app/javascript/*.* --bundle --outdir=app/assets/builds --watch
rails7-js-1        | [watch] build finished, watching for changes...
yarn run v1.22.10
rails7-app-1       | Could not find nokogiri-1.12.5, mini_portile2-2.6.1 in any of the sources
rails7-app-1       | Run `bundle install` to install missing gems.
$ sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch
rails7-app-1 exited with code 7
rails7-css-1       | Sass is watching for changes. Press Ctrl-C to stop.
rails7-css-1       | 

murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
I found problem i think, Gemfile.lock file contains nokogiri. When moving Gemfile.lock and bundle install then problem solved. 

Regards

Murat

murat.ustuntas PRO said 11 months ago on Docker on Rails 7 :
Hi,

Where and how can we change the environment property when we use this docker? 
What should we do if we want to leave the development mode and switch to the production mode?

Regards,

Murat

David Kimura PRO said 11 months ago on Docker on Rails 7 :
I would have a separate Dockerfile for the production image. In my case, if I do deploy to an x86 production environment, I would need to build the image anyways. I would do this in my CI/CD platform, but if I had to do it on my local machine (Apple Silicon SoC) then I would have to emulate the x86 CPU. So, between this and needing to have entrypoints, commands, or exposing ports, I would rather have a bit of duplication between dockerfiles and have separate environment specific ones.

Side note, this is the command that I use to build for different platforms and CPUs. 

docker buildx build -f Dockerfile --platform linux/amd64 -t registry/app_name:tag --push .

rbousquet PRO said 11 months ago on Docker on Rails 7 :
Anyone figure out how to run the rubocop plugin for Atom within the docker container?

partydrone PRO said 11 months ago on Docker on Rails 7 :
Another suggestion I would make is to decouple the Linux flavor from the Ruby version passed into the build context. For example, in your Dockerfile, FROM should read:

ARG RUBY_VERSION
FROM ruby:${RUBY_VERSION}-alpine
# …

Then in your docker-compose.yml file, pass only the Ruby version:

service:
  web:
    build:
      args:
        RUBY_VERSION: 2.6.8

The reason for doing this is the Dockerfile uses Alpine-specific commands for installing packages (apk instead of apt). If someone passes in "2.6.8-buster" then they've broken the Dockerfile and the build will fail.

David Kimura PRO said 11 months ago on Docker on Rails 7 :
I'm a bit split on that decision. I think that it does make sense. But, I would also assume anyone who is working with Docker would understand the difference. Perhaps this is a poor assumption. I think it does have some value to visibility as to the flavor being used in the docker-compose. I would probably leave this up to the team to decide on their preference as I'd be okay either way.

wh1t3d3w said 10 months ago on Docker on Rails 7 :
   Hi, I want to know if the rails application is a default generated project with `rails new` ? 
I create a project with `rails new -j esbuild --css bootstrap`, and the rails version is 7 alpha 2.
But the first different I found was, I don't have the `scripts` lines in package.json, so I can't run bin/dev , yarn alert with `build and build:css not found`.

David Kimura PRO said 10 months ago on Docker on Rails 7 :
That’s interesting. Any other errors in the  console? You do have to have yarn installed on the machine too.

Chris24680 PRO said 7 months ago on Docker on Rails 7 :
I'm having an odd issue here where if I add a gem to my app, I then am unable to start up the docker container for example, I run:
bundle add better_errors
I then close down the docker container and start it back up and I get:
ppm-app-1       | Could not find better_errors-2.9.1, coderay-1.1.3 in any of the sources                                                      
ppm-app-1       | Run `bundle install` to install missing gems.                                                                                
ppm-app-1 exited with code 7
The app then won't start up until I remove the gem from my gem file?

David Kimura PRO said 7 months ago on Docker on Rails 7 :
Are you able to run bundle install from within the running container?


Chris24680 PRO said 7 months ago on Docker on Rails 7 :
Yup if I run 
docker compose run --rm app bundle install
Then the gem installs in the container and I'm able to start the app. Though I thought the bundle volume would mean I wouldn't have to do that? Or am I misunderstanding?

Chris24680 PRO said 7 months ago on Docker on Rails 7 :
Ah I think  I know what the issue might be. My host has RVM installed, so my gems aren't installed in /usr/local/bundle, they're installed in .rvm/gems/ruby-3.1.0/gems/. Would there be any way around this?


David Kimura PRO said 7 months ago on Docker on Rails 7 :
  You are correct! Having the bundle volume doesn't map to your development machine's bundle directory. Honestly, I don't think I would want to do this anyways since there are some gems that compile native extensions. Since I develop on a macOS machine, doing this could introduce unexpected errors from the compiled gems. Having the bundle volume is still useful though if you have multiple services that rely on the application code (sidekiq, jsbundling, and cssbundling). So, when you run bundle in the app docker container, the installed gems would be available to the other services.

gabi PRO said 7 months ago on Docker on Rails 7 :
murat.ustuntas I see you mentioned about 4 months ago you found a solution for an error you were seeing regarding Nokogiri. I'm not sure I understand exactly what your solution was. You said:

I found problem i think, Gemfile.lock file contains nokogiri. When moving Gemfile.lock and bundle install then problem solved. 

What does that mean? Did you remove the Gemfile.lock? I'm seeing similar errors to your and would appreciate the help.

David Kimura PRO said 7 months ago on Docker on Rails 7 :
What issue are you running into   ? You may need to add additional platforms to the Gemfile.lock if your on a M1. Can you share the error messages?

luctus PRO said 4 months ago on Docker on Rails 7 :
Hey there! I'm having issues with nokogiri too, this is the error I get (running from M1):
/usr/local/bundle/gems/nokogiri-1.13.6-aarch64-linux/lib/nokogiri/extension.rb:7:in `require_relative': Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by /usr/local/bundle/gems/nokogiri-1.13.6-aarch64-linux/lib/nokogiri/3.1/nokogiri.so) - /usr/local/bundle/gems/nokogiri-1.13.6-aarch64-linux/lib/nokogiri/3.1/nokogiri.so (LoadError)

By the way, I also got an error related to yarn:
Error:
rails-js-1        | You installed esbuild on another platform than the one you're currently using.
rails-js-1        | This won't work because esbuild is written with native code and needs to
rails-js-1        | install a platform-specific binary executable.
rails-js-1        |
rails-js-1        | Specifically the "esbuild-darwin-arm64" package is present but this platform
rails-js-1        | needs the "esbuild-linux-arm64" package instead. People often get into this
rails-js-1        | situation by installing esbuild on Windows or macOS and copying "node_modules"
rails-js-1        | into a Docker image that runs Linux, or by copying "node_modules" between
rails-js-1        | Windows and WSL environments.

luctus PRO said 4 months ago on Docker on Rails 7 :
Oh! I found it.
We need to install the gcompat package in the alpine distro, so the Dockerfile should be like this:

RUN apk add --no-cache --update \
  build-base \
  git \
  postgresql-dev \
  nodejs \
  yarn \
  vips \
  tzdata \
  gcompat \
  && rm -rf /var/cache/apk/*


Based on [this issue](https://github.com/sparklemotion/nokogiri/issues/2430)

Raul Espinosa PRO said 21 days ago on Docker on Rails 7 :
I have no idea, I'm getting 

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "yarn": executable file not found in $PATH: unknown


Login to Comment