I am trying to run a php + mysql application on with the AWS ECS using docker. The application stack consists of a mysql, elk, php-fpm and nginx docker container. The containers all run on the same docker machine. When the Task starts, the nginx container exits with the following error: nginx: [emerg] host not found in upstream "php:9001" in /etc/nginx/conf.d/upstream.conf:1.
Nginx Dockerfile:
FROM alpine:3.4
RUN apk add --update nginx
#Clear Cache and Temp Data
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
RUN echo "upstream php-upstream { server php:9001; }" > /etc/nginx/conf.d/upstream.conf
RUN adduser -D -g '' -G www-data www-data
CMD ["nginx"]
EXPOSE 80
EXPOSE 443
RUN echo "upstream php-upstream { server php:9001; }" > /etc/nginx/conf.d/upstream.conf
The php:9001
part references to the php container, which is defined in the AWS ECS Task Definition.
nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
open_file_cache max=100;
}
daemon off;
symfony.conf:
server {
server_name _;
root /var/www/symfony/web;
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
/etc/php7/php-fpm.conf:
[symfony]
user = nobody
group = nobody
listen = 0.0.0.0:9001
pm = dynamic
pm.max_children = 1000
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE
env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER
env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD
catch_workers_output = yes
I also tried to change listen to listen = /var/run/php-fpm/php-fpm.sock
or listen = 127.0.0.1:9001
with the according changes to the nginx config, but this resulted in various other error messages.