Docker on Rails 데모 야리마스...
14558 단어 Railsdockerfiledocker-compose도커루비
소개
〝
/ l / |> 쿠 |
/_ .l > .|:H:| 쿠 l
, ―´ `ヽ, l/ .l:l l:l l.l--'ー,
γ 〽ヽ.', l:l l:l ll ヽ
{ }. ', l:l l:l .l l }
', / ', l:l l:l l l /
하고 싶은 일
개발 환경에 대하여
$ uname -a
Linux def 5.4.0-29-generic #33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ docker -v
Docker version 19.03.8, build afacb8b7f0
$ docker-compose -v
docker-compose version 1.25.0, build unknown
코드
Github의 저장소에 있습니다.
먼저 Ruby Dockerfile을 만들자.
FROM node:14.1.0-alpine3.11 as node
FROM ruby:2.7.1-alpine3.11 as ruby
ENV LANG=C.UTF-8
ENV RAILS_ENV=development
ENV RACK_ENV=development
ENV USER_NAME=un
ENV GROUP_NAME=gn
ENV USER_ID=1000
ENV GROUP_ID=1000
WORKDIR /usr/www/com/
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY Gemfile Gemfile.lock yarn.lock package.json ./
RUN addgroup -S ${GROUP_NAME} -g ${GROUP_ID} && \
adduser -S ${USER_NAME} -G ${GROUP_NAME} -u ${USER_ID} && \
apk update && apk upgrade && \
apk add build-base tzdata libxml2-dev curl imagemagick postgresql-client postgresql-dev yarn && \
if [ ${RAILS_ENV} != "production" ]; then apk add git chromium-chromedriver chromium zlib-dev xvfb wait4ports xorg-server dbus ttf-freefont mesa-dri-swrast curl udev graphviz; fi && \
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
gem update --system && \
if [ ${RAILS_ENV} = "production" ]; then bundle config set without 'production'; fi && \
bundle install --jobs 20 --retry 5 && \
bundle update && \
yarn install && \
yarn upgrade && \
yarn cache clean
USER 1000:1000
다음은 docker-compose에서도 조립합시다.
version: '3.7'
volumes:
pg-volume:
redis-sidekiq-volume:
redis-cache-store-volume:
networks:
main:
driver: bridge
services:
database-master:
image: postgres:12-alpine
ports:
- 54321:5432
environment:
POSTGRES_USER: asdf
POSTGRES_PASSWORD: qwer
POSTGRESQL_REPLICATION_MODE: master
TZ: Etc/GMT
volumes:
- pg-volume:/var/lib/postgresql/data
networks:
main:
database-replica:
image: postgres:12-alpine
ports:
- 54322:5432
environment:
POSTGRES_USER: asdf
POSTGRES_PASSWORD: qwer
POSTGRESQL_REPLICATION_USER: asdf
POSTGRESQL_REPLICATION_PASSWORD: asdf
POSTGRESQL_MASTER_HOST: database-master
POSTGRESQL_REPLICATION_MODE: slave
POSTGRESQL_MASTER_PORT_NUMBER: 5432
TZ: Etc/GMT
depends_on:
- database-master
networks:
main:
redis-cache-store:
networks:
main:
image: redis:5.0.7
environment:
TZ: Etc/GMT
ports:
- 6379:6379
volumes:
- redis-cache-store-volume:/var/lib/redis
networks:
main:
redis-sidekiq:
networks:
main:
image: redis:5.0.7
environment:
TZ: Etc/GMT
ports:
- 6380:6379
volumes:
- redis-sidekiq-volume:/var/lib/redis
networks:
main:
application-server:
user: 1000:1000
build:
context: ./rails/
target: ruby
ports:
- 3001:3000
volumes:
- ./rails/:/usr/www/com/
stdin_open: true
tty: true
environment:
REDIS_CACHE_STORE_URI: 'redis://redis-cache-store:6379/0'
REDIS_SIDEKIQ_URI: 'redis://redis-sidekiq:6379/0'
DATABASE_MASTER_HOST: 'database-master'
DATABASE_MASTER_USERNAME: 'asdf'
DATABASE_MASTER_PASSWORD: 'qwer'
DATABASE_MASTER_PORT: 5432
DATABASE_REPLICA_HOST: 'database-replica'
DATABASE_REPLICA_PASSWORD: 'qwer'
DATABASE_REPLICA_USERNAME: 'asdf'
DATABASE_REPLICA_PORT: 5432
command:
/bin/sh -c "yarn install --check-files && bundle update && bundle exec rails db:migrate:reset && bundle exec rails s -p 3000 -b '0.0.0.0' --early-hints"
links:
- redis-cache-store
- redis-sidekiq
- database-master
- database-replica
networks:
main:
동작 확인
$ docker-compose up -d && xdg-open http://localhost:3001/
이것이 보이면 안타깝습니다 ...
하지 않은 것
$ uname -a
Linux def 5.4.0-29-generic #33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ docker -v
Docker version 19.03.8, build afacb8b7f0
$ docker-compose -v
docker-compose version 1.25.0, build unknown
Github의 저장소에 있습니다.
먼저 Ruby Dockerfile을 만들자.
FROM node:14.1.0-alpine3.11 as node
FROM ruby:2.7.1-alpine3.11 as ruby
ENV LANG=C.UTF-8
ENV RAILS_ENV=development
ENV RACK_ENV=development
ENV USER_NAME=un
ENV GROUP_NAME=gn
ENV USER_ID=1000
ENV GROUP_ID=1000
WORKDIR /usr/www/com/
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY Gemfile Gemfile.lock yarn.lock package.json ./
RUN addgroup -S ${GROUP_NAME} -g ${GROUP_ID} && \
adduser -S ${USER_NAME} -G ${GROUP_NAME} -u ${USER_ID} && \
apk update && apk upgrade && \
apk add build-base tzdata libxml2-dev curl imagemagick postgresql-client postgresql-dev yarn && \
if [ ${RAILS_ENV} != "production" ]; then apk add git chromium-chromedriver chromium zlib-dev xvfb wait4ports xorg-server dbus ttf-freefont mesa-dri-swrast curl udev graphviz; fi && \
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
gem update --system && \
if [ ${RAILS_ENV} = "production" ]; then bundle config set without 'production'; fi && \
bundle install --jobs 20 --retry 5 && \
bundle update && \
yarn install && \
yarn upgrade && \
yarn cache clean
USER 1000:1000
다음은 docker-compose에서도 조립합시다.
version: '3.7'
volumes:
pg-volume:
redis-sidekiq-volume:
redis-cache-store-volume:
networks:
main:
driver: bridge
services:
database-master:
image: postgres:12-alpine
ports:
- 54321:5432
environment:
POSTGRES_USER: asdf
POSTGRES_PASSWORD: qwer
POSTGRESQL_REPLICATION_MODE: master
TZ: Etc/GMT
volumes:
- pg-volume:/var/lib/postgresql/data
networks:
main:
database-replica:
image: postgres:12-alpine
ports:
- 54322:5432
environment:
POSTGRES_USER: asdf
POSTGRES_PASSWORD: qwer
POSTGRESQL_REPLICATION_USER: asdf
POSTGRESQL_REPLICATION_PASSWORD: asdf
POSTGRESQL_MASTER_HOST: database-master
POSTGRESQL_REPLICATION_MODE: slave
POSTGRESQL_MASTER_PORT_NUMBER: 5432
TZ: Etc/GMT
depends_on:
- database-master
networks:
main:
redis-cache-store:
networks:
main:
image: redis:5.0.7
environment:
TZ: Etc/GMT
ports:
- 6379:6379
volumes:
- redis-cache-store-volume:/var/lib/redis
networks:
main:
redis-sidekiq:
networks:
main:
image: redis:5.0.7
environment:
TZ: Etc/GMT
ports:
- 6380:6379
volumes:
- redis-sidekiq-volume:/var/lib/redis
networks:
main:
application-server:
user: 1000:1000
build:
context: ./rails/
target: ruby
ports:
- 3001:3000
volumes:
- ./rails/:/usr/www/com/
stdin_open: true
tty: true
environment:
REDIS_CACHE_STORE_URI: 'redis://redis-cache-store:6379/0'
REDIS_SIDEKIQ_URI: 'redis://redis-sidekiq:6379/0'
DATABASE_MASTER_HOST: 'database-master'
DATABASE_MASTER_USERNAME: 'asdf'
DATABASE_MASTER_PASSWORD: 'qwer'
DATABASE_MASTER_PORT: 5432
DATABASE_REPLICA_HOST: 'database-replica'
DATABASE_REPLICA_PASSWORD: 'qwer'
DATABASE_REPLICA_USERNAME: 'asdf'
DATABASE_REPLICA_PORT: 5432
command:
/bin/sh -c "yarn install --check-files && bundle update && bundle exec rails db:migrate:reset && bundle exec rails s -p 3000 -b '0.0.0.0' --early-hints"
links:
- redis-cache-store
- redis-sidekiq
- database-master
- database-replica
networks:
main:
동작 확인
$ docker-compose up -d && xdg-open http://localhost:3001/
이것이 보이면 안타깝습니다 ...
하지 않은 것
Trivy에서 이미지의 안전성을 확인합니다.
결론
컴퓨터 과학 노 진보, 발전 노타 메니하, 희생 가츠키 모노 나노 데이스.
참고문헌
업데이트 내역
Reference
이 문제에 관하여(Docker on Rails 데모 야리마스...), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/seahal/items/c4f77e67d910712aef96텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)