Upgrade to Pro — share decks privately, control downloads, hide ads and more …

當 Rails 遇上 Docker,環境部署原來是這樣!?

Johnson
August 18, 2019
300

當 Rails 遇上 Docker,環境部署原來是這樣!?

Johnson

August 18, 2019
Tweet

Transcript

  1. h t t p s : / / 5 x

    r u b y . t w / 當 R ail s 遇上 Doc ker
 環境部署原來 是這樣!?
  2. Server Host OS App A App B Bins/Libs Bins/Libs Server

    Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  3. Server Host OS App A App B Bins/Libs Bins/Libs Server

    Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  4. Server Host OS App A App B Bins/Libs Bins/Libs Guest

    OS Guest OS Server Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  5. Server Hypervisor Host OS App A App B Bins/Libs Bins/Libs

    Guest OS Guest OS Server Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  6. Server Hypervisor Host OS App A App B Bins/Libs Bins/Libs

    Guest OS Guest OS Server Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  7. Server Hypervisor Host OS App A App B Bins/Libs Bins/Libs

    Guest OS Guest OS Server Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker Docker Engine
  8. Server Hypervisor Host OS App A App B Bins/Libs Bins/Libs

    Guest OS Guest OS Server Docker Engine Host OS App A App B Bins/Libs Bins/Libs 虛擬機 vs Docker 虛擬機 Docker
  9. 虛擬機 vs Docker 虛擬機 Docker 啟動速度:秒 性能:接近原⽣生 運⾏行行密度:幾千 隔離效果:共⽤用 Kernel

    啟動速度:分鐘 性能:較弱 運⾏行行密度:幾⼗十 隔離效果:完全隔離
  10. 虛擬機 vs Docker 虛擬機 Docker 啟動速度:秒 性能:接近原⽣生 運⾏行行密度:幾千 隔離效果:共⽤用 Kernel

    跨平台,圖形介⾯面 啟動速度:分鐘 性能:較弱 運⾏行行密度:幾⼗十 隔離效果:完全隔離 跨平台,圖形介⾯面
  11. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY . /app ENV RAILS_ENV production RUN bundle install CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  12. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Image

    圖片來來源:https://www.flaticon.com
  13. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image Docker Image 圖片來來源:https://www.flaticon.com
  14. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  15. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    User Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  16. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    User http Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  17. 用 Docker 部署 Rails 網站到 VPS VPS Local CloudFlare Docker

    Hub User Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  18. 用 Docker 部署 Rails 網站到 VPS VPS Local CloudFlare Docker

    Hub User http https Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  19. ‧ 建立 Rails 專案,並使用 scaffold
 
 rails new example_app rails

    generate scaffold post title:string body:text 準備動作
  20. ‧ 建立 Rails 專案,並使用 scaffold
 
 ‧ 改成 PostgreSQL rails

    new example_app rails generate scaffold post title:string body:text 準備動作
  21. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  22. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  23. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  24. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  25. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  26. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production RUN gem install bundler RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  27. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  28. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  29. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  30. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  31. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  32. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  33. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY . /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  34. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  35. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  36. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  37. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  38. docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: - "POSTGRES_USER=postgres"

    - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  39. docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: - "POSTGRES_USER=postgres"

    - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  40. docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: - "POSTGRES_USER=postgres"

    - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  41. Dockerfile FROM ruby:2.4.1 MAINTAINER johnson <[email protected]> RUN apt-get update &&

    apt-get install -y build-essential libpq-dev nodejs vim postgis RUN mkdir /app WORKDIR /app COPY Gemfile /app/Gemfile COPY Gemfile.lock /app/Gemfile.lock ENV RAILS_ENV production ENV BUNDLER_VERSION 2.0.1 RUN gem install bundler -v 2.0.1 RUN bundle install COPY . /app CMD rake db:migrate assets:precompile && puma -C config/puma.rb
  42. docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: - "POSTGRES_USER=postgres"

    - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  43. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  44. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  45. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com ‧ 本地打包 Docker Image ‧ 本地 Docker Image 上傳 Docker Hub ‧ VPS 從 Docker Hub 下載 Docker Image ‧ 本地上傳 docker-compose.yml 到 VPS ‧ 在 VPS 啟動 docker-compose.yml
  46. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com ‧ 本地打包 Docker Image ‧ 本地 Docker Image 上傳 Docker Hub ‧ VPS 從 Docker Hub 下載 Docker Image ‧ 本地上傳 docker-compose.yml 到 VPS ‧ 在 VPS 啟動 docker-compose.yml
  47. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com ‧ 本地打包 Docker Image ‧ 本地 Docker Image 上傳 Docker Hub ‧ VPS 從 Docker Hub 下載 Docker Image ‧ 本地上傳 docker-compose.yml 到 VPS ‧ 在 VPS 啟動 docker-compose.yml
  48. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com ‧ 本地打包 Docker Image ‧ 本地 Docker Image 上傳 Docker Hub ‧ VPS 從 Docker Hub 下載 Docker Image ‧ 本地上傳 docker-compose.yml 到 VPS ‧ 在 VPS 啟動 docker-compose.yml
  49. 用 Docker 部署 Rails 網站到 VPS VPS Local Docker Hub

    Docker Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com ‧ 本地打包 Docker Image ‧ 本地 Docker Image 上傳 Docker Hub ‧ VPS 從 Docker Hub 下載 Docker Image ‧ 本地上傳 docker-compose.yml 到 VPS ‧ 在 VPS 啟動 docker-compose.yml
  50. 完成繁瑣的五步驟 #!/usr/bin/env ruby p '本地打包 Docker Image' `docker build .

    -t johnsonzhan121/example_app` p '本地 Docker Image 上傳 Docker Hub' `docker push johnsonzhan121/example_app` p '本地上傳 docker-compose.yml 到 VPS' `scp docker-compose.yml [email protected]:/home/example_app` p 'VPS 從 Docker Hub 下載 Docker Image' `ssh [email protected] 'docker pull johnsonzhan121/example_app'` p '在 VPS 啟動 docker-compose.yml' `ssh [email protected] 'cd /home/example_app && docker-compose up'`
  51. 完成繁瑣的五步驟 #!/usr/bin/env ruby p '本地打包 Docker Image' `docker build .

    -t johnsonzhan121/example_app` p '本地 Docker Image 上傳 Docker Hub' `docker push johnsonzhan121/example_app` p '本地上傳 docker-compose.yml 到 VPS' `scp docker-compose.yml [email protected]:/home/example_app` p 'VPS 從 Docker Hub 下載 Docker Image' `ssh [email protected] 'docker pull johnsonzhan121/example_app'` p '在 VPS 啟動 docker-compose.yml' `ssh [email protected] 'cd /home/example_app && docker-compose up'`
  52. CloudFlare VPS Local Docker Hub User http Docker Image docker-compose.yml

    Docker Image 圖片來來源:https://www.flaticon.com
  53. CloudFlare VPS Local CloudFlare Docker Hub User Docker Image docker-compose.yml

    Docker Image 圖片來來源:https://www.flaticon.com
  54. CloudFlare VPS Local CloudFlare Docker Hub User http https Docker

    Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  55. 大功告成 VPS Local CloudFlare Docker Hub User http https Docker

    Image docker-compose.yml Docker Image 圖片來來源:https://www.flaticon.com
  56. server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log

    main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } /etc/nginx/conf.d/default.conf
  57. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  58. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  59. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  60. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  61. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  62. default.conf server { listen 80; server_name dockerapp.ga; location / {

    proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  63. ‧ 從 config/puma.rb 修改連線的 Port
 
 #port ENV.fetch("PORT") { 80

    } bind "unix:///app/tmp/sockets/puma.sock" 準備動作
  64. ‧ 從 config/puma.rb 修改連線的 Port
 
 #port ENV.fetch("PORT") { 80

    } bind "unix:///app/tmp/sockets/puma.sock" 準備動作 server { listen 80; server_name dockerapp.ga; location / { proxy_pass http://unix:/app/tmp/sockets/puma.sock; proxy_set_header X-Forwarded-Host dockerapp.ga; } }
  65. 更新 docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: -

    "POSTGRES_USER=postgres" - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  66. 更新 docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: -

    "POSTGRES_USER=postgres" - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  67. 更新 docker-compose.yml version: '3' services: db: image: postgres:9.6 environment: -

    "POSTGRES_USER=postgres" - "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true restart: always depends_on: - db ports: - "80:80" networks: - johnson networks: johnson:
  68. app: build: . environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4dcf3039eccd59cf787cfb9… - RAILS_SERVE_STATIC_FILES=true

    restart: always depends_on: - db ports: - "80:80" volumes: - /tmp/sockets:/app/tmp/sockets networks: - johnson 更新 docker-compose.yml
  69. app: image: johnsonzhan121/example_app:latest environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4df56c3f41d8dc270ee48f5… - RAILS_SERVE_STATIC_FILES=true

    restart: always volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - db networks: - johnson nginx: image: johnsonzhan121/example_nginx:latest ports: - "80:80" volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - app networks: - johnson 更新 docker-compose.yml
  70. app: image: johnsonzhan121/example_app:latest environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4df56c3f41d8dc270ee48f5… - RAILS_SERVE_STATIC_FILES=true

    restart: always volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - db networks: - johnson nginx: image: johnsonzhan121/example_nginx:latest ports: - "80:80" volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - app networks: - johnson 更新 docker-compose.yml
  71. version: '3' services: db: image: postgres:9.6 environment: - "POSTGRES_USER=postgres" -

    "POSTGRES_PASSWORD=postgres" volumes: - ./pg-data:/var/lib/postgresql/data ports: - "5432:5432" networks: - johnson app: image: johnsonzhan121/example_app:latest environment: - DATABASE_URL=postgres://postgres:postgres@db/postgres - SECRET_KEY_BASE=8527f4cd4df56c3f41d8dc… - RAILS_SERVE_STATIC_FILES=true restart: always volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - db networks: - johnson nginx: image: johnsonzhan121/example_nginx:latest ports: - "80:80" volumes: - /tmp/sockets:/app/tmp/sockets depends_on: - app networks: - johnson networks: johnson: 更新 docker-compose.yml
  72. #!/usr/bin/env ruby p '本地打包 Docker Image' `docker build . -t

    johnsonzhan121/example_app` p '本地 Docker Image 上傳 Docker Hub' `docker push johnsonzhan121/example_app` p '本地上傳 docker-compose.yml 到 VPS' `scp docker-compose.yml [email protected]:/home/example_app` p 'VPS 從 Docker Hub 下載 Docker Image' `ssh [email protected] 'docker pull johnsonzhan121/example_app'` p '在 VPS 啟動 docker-compose.yml' `ssh [email protected] 'cd /home/example_app && docker-compose up'` 更新自動化程式
  73. #!/usr/bin/env ruby p '本地打包 Docker Image' `docker build . -t

    johnsonzhan121/example_app` `docker build docker/nginx/. -t johnsonzhan121/example_nginx` p '本地 Docker Image 上傳 Docker Hub' `docker push johnsonzhan121/example_app` `docker push johnsonzhan121/example_nginx` p '本地上傳 docker-compose.yml 到 VPS' `scp docker-compose.yml [email protected]:/home/example_app` p 'VPS 從 Docker Hub 下載 Docker Image' `ssh [email protected] 'docker pull johnsonzhan121/example_app’` `ssh [email protected] 'docker pull johnsonzhan121/example_nginx'` p '在 VPS 啟動 docker-compose.yml' `ssh [email protected] 'cd /home/example_app && docker-compose up'` 更新自動化程式
  74. #!/usr/bin/env ruby p '本地打包 Docker Image' `docker build . -t

    johnsonzhan121/example_app` `docker build docker/nginx/. -t johnsonzhan121/example_nginx` p '本地 Docker Image 上傳 Docker Hub' `docker push johnsonzhan121/example_app` `docker push johnsonzhan121/example_nginx` p '本地上傳 docker-compose.yml 到 VPS' `scp docker-compose.yml [email protected]:/home/example_app` p 'VPS 從 Docker Hub 下載 Docker Image' `ssh [email protected] 'docker pull johnsonzhan121/example_app’` `ssh [email protected] 'docker pull johnsonzhan121/example_nginx'` p '在 VPS 啟動 docker-compose.yml' `ssh [email protected] 'cd /home/example_app && docker-compose up'` 更新自動化程式