我正在使用AWS Fargate部署我的API服务器。我运行以下命令:
docker-compose build
ecs-cli push xxx.dkr.ecr.us-east-1.amazonaws.com/api-server/nginx:latest
ecs-cli push xxx.dkr.ecr.us-east-1.amazonaws.com/api-server/uwsgi:latest
ecs-cli up --keypair xxx --capability-iam \
--vpc vpc-xxx \
--subnets subnet-xxx,subnet-yyy \
--security-group sg-xxx \
--force
ecs-cli compose --file docker-compose.production.yml --ecs-params ecs-params.yml up --create-log-groups
在最后一步中出现以下错误:
INFO[0001] Using ECS task definition TaskDefinition="api_server:22"
WARN[0002] Failed to create log group api-server-nginx in us-east-1: The specified log group already exists
WARN[0002] Failed to create log group api-server-uwsgi in us-east-1: The specified log group already exists
WARN[0002] No log groups to create; no containers use 'awslogs'
INFO[0004] Starting container... container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx
INFO[0004] Starting container... container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi
INFO[0004] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=RUNNING lastStatus=PROVISIONING taskDefinition="api_server:22"
INFO[0004] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=RUNNING lastStatus=PROVISIONING taskDefinition="api_server:22"
INFO[0018] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=RUNNING lastStatus=PROVISIONING taskDefinition="api_server:22"
INFO[0018] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=RUNNING lastStatus=PROVISIONING taskDefinition="api_server:22"
INFO[0032] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0032] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0045] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0045] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0058] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0058] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=RUNNING lastStatus=PENDING taskDefinition="api_server:22"
INFO[0072] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0072] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0086] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0086] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0098] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0098] Describe ECS container status container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=STOPPED lastStatus=DEPROVISIONING taskDefinition="api_server:22"
INFO[0111] Stopped container... container=xxxx-xxxx-xxxx-xxxx-xxxx/uwsgi desiredStatus=STOPPED lastStatus=STOPPED taskDefinition="api_server:22"
INFO[0111] Stopped container... container=xxxx-xxxx-xxxx-xxxx-xxxx/nginx desiredStatus=STOPPED lastStatus=STOPPED taskDefinition="api_server:22"
我检查了CloudWatch日志:
realpath() of uwsgi.ini failed: No such file or directory [core/utils.c line 3654]
我认为此错误是由volumes
中的docker-compose.production.yml
设置引起的。但是,我不了解确切原因以及如何在Fargate设置中修复它。
您有什么想法吗?
谢谢。
docker-compose.yml
version: "3"
services:
uwsgi:
build: ./flask_uwsgi
volumes:
- ./flask_uwsgi:/var/www/
- ~/.aws/config:/root/.aws/config
ports:
- "3031:3031"
nginx:
build: ./nginx
ports:
- "4231:80"
docker-compose.production.yml
version: "3"
services:
uwsgi:
image: xxx.dkr.ecr.us-east-1.amazonaws.com/api-server/uwsgi:latest
ports:
- "3031:3031"
logging:
driver: awslogs
options:
awslogs-group: api-server-uwsgi
awslogs-region: us-east-1
awslogs-stream-prefix: api-server-uwsgi
nginx:
image: xxx.dkr.ecr.us-east-1.amazonaws.com/api-server/nginx:latest
ports:
- "80:80"
logging:
driver: awslogs
options:
awslogs-group: api-server-nginx
awslogs-region: us-east-1
awslogs-stream-prefix: api-server-nginx
ecm-params.yml
version: 3
task_definition:
ecs_network_mode: awsvpc
task_execution_role: ecsTaskExecutionRole
task_size:
cpu_limit: 256
mem_limit: 512
services:
uwsgi:
cpu_shares: 100
mem_limit: 268435456
nginx:
cpu_shares: 100
mem_limit: 268435456
run_params:
network_configuration:
awsvpc_configuration:
subnets:
- subnet-xxx
- subnet-yyy
security_groups:
- sg-xxx
assign_public_ip: ENABLED
flask_uwsgi> Dockerfile
# base image
FROM python:3.6
RUN mkdir /var/www
WORKDIR /var/www
# install python libraries
COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
CMD ["uwsgi", "--ini", "uwsgi.ini"]
uwsgi> uwsgi.ini
[uwsgi]
wsgi-file=/var/www/src/run.py
callable=app
master=true
processes=1
chmod-socket=666
vacuum=true
die-on-term=true
py-autoreload=1
socket=:3031
nginx> Dockerfile
FROM nginx:latest
ADD nginx.conf /etc/nginx/nginx.conf
CMD ["nginx", "-g", "daemon off;", "-c", "/etc/nginx/nginx.conf"]
nginx> nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream uwsgi {
server 172.0.0.1:3031;
}
server {
listen 80;
charset utf-8;
location / {
include uwsgi_params;
proxy_pass http://uwsgi;
}
}
}