We are running a Rails application with Sidekiq for background processing. Our Sidekiq setup includes multiple queues we want to run and scale independently. Is there a way to parametrize the Dockerfile?
Hi @FlorianSuchan , thanks for asking here.
We plan to officially support customizing the CMD
command via the web interface in the coming release. cc @a_carrano In the meantime, I propose to use the solution below.
Temporary solution
# syntax=docker/dockerfile:1
FROM ruby:2.7
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
COPY . .
EXPOSE 3000
# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
Let’s say you want to use this Dockerfile and be able to adapt the CMD
command with
["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
to run your app in API mode and
["bundle", "exec", "sidekiq"]
to run your app in worker mode with Sidekiq
Step 1
In Qovery, create an environment variable CMD_TO_RUN
and put the command you need to run as a value. E.g
Step 2
In your Dockerfile, change your CMD command for the following one
Example for a rails app
# syntax=docker/dockerfile:1
FROM ruby:2.7
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
COPY . .
EXPOSE 3000
# Declare arg we use in the Dockerfile
ARG CMD_TO_RUN
# Assign arg from the Dockerfile with the env var injected in parameter of the build and run process
ENV CMD_TO_RUN $CMD_TO_RUN
# Exec CMD with the appropriate parameters
CMD ["sh", "-c", "${CMD_TO_RUN}"]
Step 3
You can repeat the step 1 for your second application and change the CMD_TO_RUN
env var value.
Note: I didn’t try what I suggest but it should work. Let me know how it goes. Then I can fix the answer. Thx @FlorianSuchan
Hi @rophilogene, works like a charm thank you very much
Is this still the only way to have custom start commands?
It’s a workaround. We plan to make it customizable in the application settings. Cc @a_carrano