This Gist helps to build and start a simple Rails application in a single Docker container (no docker-compose needed).
- Go to your projects folder
cd /home/user/my_projects
- Run a temporary
ruby:2.x
container that will install Rails
docker run --rm -v "${PWD}":/application -w /application ruby:2.7 /bin/bash -c "gem install rails -v '6.1' && rails new simple_rails_app_container --minimal ."
- Change the newly created folder's permissions to match the current user
sudo chown -R ${USER:=$(/usr/bin/id -run)}:$USER simple_rails_app_container
- Enter the newly created folder
cd /home/user/my_projects/simple_rails_app_container
- Create a Dockerfile with this content
FROM ruby:2.7
RUN apt-get update -qq && \
apt-get install -y nodejs && \
apt-get clean && \
bundle config --global frozen 1
WORKDIR /application
COPY Gemfile 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"]
- Build the custom image
docker build -t simple_rails_app_container:1.0 .
- Run it
docker run --name simple_rails_app_container-1 -v "${PWD}":/application -p3000:3000 simple_rails_app_container:1.0
- Try it in your browser: http://0.0.0.0:3000