Note tạm vào đây từ từ viết chi tiết sau

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FROM ruby:2.7.1

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-key update \
&& apt-get update -qq \
&& apt-get install -y --no-install-recommends build-essential libpq-dev nodejs yarn less \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*

WORKDIR /app

COPY Gemfile* ./

CMD ["/app/docker_bash.sh"]

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: "3"
services:
api:
build: .
volumes:
- .:/app
- bundle:/usr/local/bundle
ports:
- 3000:3000
depends_on:
- db
tty: true
stdin_open: true

db:
image: mysql:5.7
volumes:
- mysql_data:/var/lib/mysql
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: root

volumes:
mysql_data:
bundle:

docker_bash.sh

1
2
3
4
5
#!/bin/sh
rm -f tmp/pids/server.pid
bundle install -j4 --retry 5
bundle exec rails db:prepare
bundle exec rails s -b '0.0.0.0'