В целях изучения Docker взялся за связку php и nginx. Связать их вместе не получилось.
Моя последовательность действий:
Запускаю контейнер с php первым (т.к nginx его потом использует):
sudo docker run -d --name php_container php:fpm
Создаю Dockerfile для nginx:
from nginx
COPY default.host /etc/nginx/conf.d/default.conf
Содержимое default.host:
server {
listen 80 default;
root /var/www/html;
index index.php;
location / {
try_files $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
Собираю образ с Nginx:
sudo docker build -t nginx_image .
Запускаю контейнер:
sudo docker run -p 80:80 --link php_container:php -v /home/yr/index.php:/var/www/html/index.php nginx_image
Перехожу на 0.0.0.0:80 и браузер выводит File not found. В логах контейнера nginx:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/06/06 10:47:55 [notice] 1#1: using the "epoll" event method
2021/06/06 10:47:55 [notice] 1#1: nginx/1.21.0
2021/06/06 10:47:55 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)
2021/06/06 10:47:55 [notice] 1#1: OS: Linux 5.12.8-300.fc34.x86_64
2021/06/06 10:47:55 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/06/06 10:47:55 [notice] 1#1: start worker processes
2021/06/06 10:47:55 [notice] 1#1: start worker process 30
2021/06/06 10:47:55 [notice] 1#1: start worker process 31
2021/06/06 10:47:55 [notice] 1#1: start worker process 32
2021/06/06 10:47:55 [notice] 1#1: start worker process 33
2021/06/06 10:48:14 [error] 31#31: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.2:9000", host: "0.0.0.0"
172.17.0.1 - - [06/Jun/2021:10:48:14 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36" "-"