Closed iwaseasahi closed 3 years ago
docker image を作成します。
$ docker build -t ecs-rails-sample -f docker/rails/Dockerfile .
上記の URL でアクセルできると予想していたのですが、できず。
-b 0.0.0.0というオプションをつけると、仮想マシンが持っている全てのネットワークインターフェースにバインディングされるため、仮想環境外部からアクセスできる。
https://qiita.com/Masato338/items/f162394fbc37fc490dfb
ということなので、http://18.183.107.155:3000/ でアクセスできるはず。
セキュリティグループのインバウンドで 3000 port を開けたらアクセスできました。
さらに nginx を追加していきます。
これが /etc/nginx/nginx.conf
の中身です。
nginx_1 |
nginx_1 | user nginx;
nginx_1 | worker_processes auto;
nginx_1 |
nginx_1 | error_log /var/log/nginx/error.log notice;
nginx_1 | pid /var/run/nginx.pid;
nginx_1 |
nginx_1 |
nginx_1 | events {
nginx_1 | worker_connections 1024;
nginx_1 | }
nginx_1 |
nginx_1 |
nginx_1 | http {
nginx_1 | include /etc/nginx/mime.types;
nginx_1 | default_type application/octet-stream;
nginx_1 |
nginx_1 | log_format main '$remote_addr - $remote_user [$time_local] "$request" '
nginx_1 | '$status $body_bytes_sent "$http_referer" '
nginx_1 | '"$http_user_agent" "$http_x_forwarded_for"';
nginx_1 |
nginx_1 | access_log /var/log/nginx/access.log main;
nginx_1 |
nginx_1 | sendfile on;
nginx_1 | #tcp_nopush on;
nginx_1 |
nginx_1 | keepalive_timeout 65;
nginx_1 |
nginx_1 | #gzip on;
nginx_1 |
nginx_1 | include /etc/nginx/conf.d/*.conf;
nginx_1 | }
docker-compose の volumes について https://www.ogis-ri.co.jp/otc/hiroba/technical/docker/part4.html
Unixドメインソケット https://ascii.jp/elem/000/001/415/1415088/
Use volumes https://docs.docker.com/storage/volumes/
$ docker build -t ecs-rails-sample-nginx -f docker/nginx/Dockerfile .
ECS に deploy してみましたが、以下のエラーになりました。 https://ap-northeast-1.console.aws.amazon.com/cloudwatch/home?region=ap-northeast-1#logsV2:log-groups/log-group/$252Fecs$252Fecs-rails-sample-task/log-events/ecs$252Fecs-rails-sample-nginx$252F1ab2e7f7f4c548e1a990a66cdbb0c460
おそらくローカルでも発生した volumes の問題だと思われます。
ちゃんと 3000 port も閉じています。 http://35.76.111.26:3000/
500 エラーも表示できました。 http://35.76.111.26/500.html
無事に素の rails を ECS 化できたので close します。
背景
https://github.com/iwaseasahi/christchurches-map/issues/782
上記 issue で ECS 化にチャレンジしましたが、全くわからない状態で ECS にするのは難易度が高いので、まずは素の rails を ECS 化してきます。
目的
ECS を理解する
完成条件
rails new したばかりの rails を ECS で動かすこと