1.新建空目錄,名字能夠叫Railsnode
2.新建Dockerfile並添加以下內容web
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp
3.新建Gemfile並添加以下內容sql
source ‘https://rubygems.org‘
gem ‘rails‘, ‘5.2.0‘
4.建立一個空Gemfile.lock
來構建咱們的Dockerfile
docker
touch Gemfile.lock
5.編寫
docker-compose.yml數據庫
version: 「3」
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data web: build: . command: bundle exec rails s -p 3000 -b ‘0.0.0.0‘ volumes: - .:/myapp ports: - "3000:3000" depends_on: - db
6.有了上面這四個文件,如今能夠使用docker-compose run生成Rails骨架應用程序瀏覽器
docker-compose run web rails new . --fordatabase=postgresql
7.受權ruby
sudo chown -R $USER:$USER .
8.構建app
docker-compose build
9.用如下內容替換內容config/database.yml
post
default: &default adapter: postgresql encoding: unicode host: db username: postgres password: pool: 5 development: <<: *default database: myapp_development test: <<: *default database: myapp_test
10.啓動應用程序ui
docker-compose up
控制檯輸出:
11.瀏覽器輸入:http://IP:3000/回車 出現以下界面表示成功
12.最後,您須要建立數據庫。在另外一個終端中,運行
docker-compose run web rake db:create
控制檯輸出:
轉換爲utf-8