`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. 😉
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:
 ☒, 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.
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.
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?
 ☒ 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.
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/*
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
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?
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Â Â Â Â |Â
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?
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.Â
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.
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.
 ☒ 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`.
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?
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?
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?
 ☒ 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.
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.
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?
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.
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
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:
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.
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ş
I could not change the Dockerfile.dev. It is as in the source file.Â
volumes:
 bundle:
 node_modules:
 postgres:
Also, my docker version is Docker version 20.10.9, build c2ea9bc90b
Regards
Murat
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
Side note, this is the command that I use to build for different platforms and CPUs.Â
Then in your docker-compose.yml file, pass only the Ruby version:
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.
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`.
What does that mean? Did you remove the Gemfile.lock? I'm seeing similar errors to your and would appreciate the help.
By the way, I also got an error related to yarn:
Error:
RUN apk add --no-cache --update \
Based on [this issue](https://github.com/sparklemotion/nokogiri/issues/2430)
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