Dockerize New Rails5 Application

FROM ruby:2.5
MAINTAINER ayesha306
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY /usr/bin/
RUN chmod +x /usr/bin/
# Start the main process.
CMD ["rails", "server", "-b", ""]
touch Gemfile
touch Gemfile.lock
source ''
gem 'rails', '~>5'
#!/bin/bashset -e# Remove a potentially pre-existing for Rails.rm -f /myapp/tmp/pids/ Then exec the container’s main process (what’s set as CMD in the Dockerfile).exec “$@”
version: '3'
image: postgres
- ./tmp/db:/var/lib/postgresql/data
build: .
command: bash -c "rm -f tmp/pids/ && bundle exec rails s -p 3000 -b ''"
- .:/myapp
- "3001:3000"
- db

Build the project

docker-compose run web rails new . --force --no-deps --database=postgresql
$ ls -l
docker-compose build

Connect the database

default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
pool: 5
<<: *default
database: myapp_development
<<: *default
database: myapp_test
docker-compose up
docker-compose run web rake db:create

View the Rails welcome page!

docker ps #this command will show the running container
docker exec -it <container id> bash
rails console
docker-compose down

Restart the application

Rebuild the application

ports: - "3001:3000"


docker login
docker push ayesha306/myapp:latest





Software Engineer — Openshift CoreOS

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Linus / Unix Stuff

LatticeX Foundation Reached Strategic Partnership with xNFT Protocol

Deploy a simple flask application in Google Cloud Run

Appvn apk for android mobiles and drugs: Download appvn Apk is the first-class app keep to download…

@Charles eugene hill | 11 - 17 - 1983

Handling Screen Orientation Changes in Capacitor Apps

10 New Languages for Perspective API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ayesha Kaleem

Ayesha Kaleem

Software Engineer — Openshift CoreOS

More from Medium

Getting Started with ScyllaDB Cloud Using Node.js Part 1

Connect MongoDB Docker Container With Robo 3T and Mongo Express

A Container illustration from Docker

Intelligent Systems with Internet of Things (IoT) -5 (Database)

A Node.js configuration provider reading files, environment and arguments