M
M
michaelromanov902021-02-04 08:13:44
PHP
michaelromanov90, 2021-02-04 08:13:44

Why can't I run docker bundle nginx+php-fpm?

Good afternoon.

I'm just studying the issue - so far there are no goals to mount the directory. Trying to get rid of error 502 (at localhost:8080 ).

1. There is a project structure

601b7f5186432178473687.jpeg

1.1. I have a config file for nginx ( localhost:8080 )

server {
    listen 80;
    charset utf-8;
    index index.php index.html;
    root /app/public;


    location / {
        try_files $uri /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_read_timeout 300;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}


1.2. php file
<?php
print "Hi!";
?>


2. And docker files
2.1 Docker file for nginx ( \site\docker\nginx\Dockerfile)
FROM nginx:1.17-alpine


#COPY ./docker/nginx/conf.d /etc/nginx/conf.d
COPY ./././docker/nginx/conf.d ./etc/nginx/conf.d




#COPY ./public ./public
COPY ./public ./app/public

WORKDIR /app


2.2. docker file for php-fpm (\site\docker\php-fpm\Dockerfile)

3. I build (everything is ok, no errors)
docker build --file=site/docker/nginx/Dockerfile --tag=site-nginx site
docker build --file=site/docker/php-fpm/Dockerfile --tag=site-php-fpm site
docker network create site
docker run -d --network site --name php-fpm site-php-fpm
docker run -d --network site --name nginx -p 8080:80 site-nginx


4. check paths in
nginx containers :
/etc/nginx/conf.d/default.conf - copied
/app/public/index.php - copied
php-fpm :
/app/public/index.php - copied

5. Result
502 Bad Gateway
nginx/1.17.10

6. Logs
while
nginx logs :
/var/log/nginx/access.log - empty
/var/log/nginx/error.log - empty

php-fpm :
no separate log
apatch logs - empty

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-02-04
@q2digger

If you make two different containers with your hands and they must be linked, but for some reason you don’t want to use docker-compose, don’t forget to link between them. example.
1. took off first

docker run -d --network site --name one -P nginxdemos/hello

2. took off the second, linked to the first
docker run -d --network site --name two --link one -P nginxdemos/hello

2. status
CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS          PORTS                   NAMES
40132d06643d   nginxdemos/hello   "nginx -g 'daemon of…"   3 seconds ago    Up 1 second     0.0.0.0:32772->80/tcp   two
5b6100f38e7d   nginxdemos/hello   "nginx -g 'daemon of…"   56 seconds ago   Up 54 seconds   0.0.0.0:32771->80/tcp   one

4. go to container two, check the link
docker exec -it 5b6 /bin/sh
/ # ping one
PING one (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.081 ms
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.128 ms

Homework: go to the nginx container check the availability of the php-fpm container (in the nginx config you have exactly this name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question