Skip to content

Commit 0819a81

Browse files
authored
Add CMD and refactor ENTRYPOINT in the Docker generator (rails#46778)
* Add CMD and refactor ENTRYPOINT The CMD will run by default when you run the container without supplying any arguments but you can choose to overwrite this at runtime by doing: docker container run -it myapp rails c The ENTRYPOINT will only create or migrate the database when the default CMD is invoked. If you choose to run a different command such as the rails console or a background worker process the db:prepare command will not run. * Remove extra space from ENTRYPOINT comment
1 parent 46f9988 commit 0819a81

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ RUN bundle exec bootsnap precompile --gemfile app/ lib/
4444
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
4545
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
4646

47-
# Entrypoint prepares database and starts app on 0.0.0.0:3000 by default,
48-
# but can also take a rails command, like "console" or "runner" to start instead.
47+
# Entrypoint prepares the database.
4948
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
49+
50+
# Start the server by default, this can be overwritten at runtime.
5051
EXPOSE 3000
52+
CMD ["./bin/rails", "server"]
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#!/bin/sh
22

3-
if [ $# -eq 0 ]; then
4-
# Create new or migrate existing database
3+
# If running the rails server then create or migrate existing database
4+
if [ "${*}" == "./bin/rails server" ]; then
55
./bin/rails db:prepare
6-
7-
# Start the server by default
8-
exec bin/rails server
9-
else
10-
# Allow other commands, like console or runner, to be called
11-
exec bin/rails "$@"
126
fi
7+
8+
exec "${@}"

0 commit comments

Comments
 (0)