不知道為啥拿現成image都沒辦法成功部署上去…
只好自己build一個QQ
這邊先開好一個folder
然後建立好laravel專案1
2
3mkdir ecr-test
cd ecr-test
composer create-project laravel/laravel project--name --prefer-dist
然後建立nginx的config ecr.conf
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41server {
listen 80;
root /var/www/html/public;
index index.php;
location / {
# 先 try_files 確認是否有靜態文件存在,若沒有則將請求重寫為 index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# optionally set the value of the environment variables used in the application
# fastcgi_param APP_ENV prod;
# fastcgi_param APP_SECRET <app-secret-id>;
# fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ \.php$ {
return 404;
}
location ~ /\.ht {
deny all;
}
}
建立Dockerfile
1 | # 這個 Docker image 的基礎映像 |
執行建立docker image
1 | docker build -t ecr-test . |
建立完之後連去 http://localhost:8080
查看一下有沒有成功
如果看到成功建立的話就可以準備推上ECR
推上ecr
這邊用ap-southeast-1區來示範
Create ECR repository1
aws --region ap-southeast-1 ecr create-repository --repository-name ecr-test
打tag1
docker tag ecr-test 123456789123.dkr.ecr.ap-southeast-1.amazonaws.com/ecr-test
登入ECR 並push image1
2
3eval $(aws --region ap-southeast-1 ecr get-login --no-include-email)
docker push 123456789123.dkr.ecr.ap-southeast-1.amazonaws.com/ecr-test
部署Fargate
建立Loadbalance 和Fargate app
1 | fargate --region ap-southeast-1 lb create ecr-test-lb --port 80 |
部署後可以查詢狀態
fargate狀態查詢及刪除
狀態查詢1
2
3fargate --region ap-southeast-1 service list
fargate --region ap-southeast-1 service info ecr-test
刪除fargate app/Loadbalancer
1 | fargate --region ap-southeast-1 service scale ecr-test-app 0 |