For local development I try to build a docker image on top of jelastic/nginxphp as suggested in https://docs.jelastic.com/building-custom-container/ . Unfortunately I can not see any server (php-fpm or nginx) once I start the image.
docker run -p 8080:80 jelastic/nginxphp:1.14.2-php-7.2.9
ā ~ curl 127.0.0.1:8080
curl: (52) Empty reply from server
I can see that systemd gets started, but I do not see php-fpm or nginx.
ā ~ docker exec 55a454cf01ad ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 191276 10172 ? Ssl 07:58 0:00 /usr/bin/qemu-x86_64 /usr/lib/systemd/systemd
root 9 0.0 0.0 200788 10408 ? Rl+ Nov25 0:00 /usr/bin/ps aux
I wonder how to build my app on top of this image. Is there any documentation or is there an example for jelastic/nginxphp?
Generally, the jelastic/nginxphp docker image is built in a quite different way from, for example, the Nginx repo from the Docker library - that's because it was designed to be launched on Virtuozzo DevOps platform and have the support of all the functionality and automatizations provided there.
If you run
'docker inspect jelastic/nginxphp:1.14.2-php-7.2.9', you can see
"Cmd": [
"/usr/lib/systemd/systemd"
],
To run the image locally, you need to override the CMD during launch
docker run -p 8080:80 jelastic/nginxphp:1.14.2-php-7.2.9 /usr/sbin/nginx '-g daemon off;'
Related
I have a docker (php:7-fpm-alpine) container with supervisor installed. It is added to a default installation by:
RUN apk add nginx composer php7-fpm php7-session supervisor && \
... ... ...
cp supervisord.conf /etc/supervisor.d/conf.ini
Supervisor has its default config (didn't change it after installation), I have added my own config to append to it (supervisord.conf):
[program:php-fpm7]
command = /usr/sbin/php-fpm7 --nodaemonize --fpm-config /etc/php7/php-fpm.d/www.conf
autostart=true
autorestart=true
priority=5
stdout_logfile=/var/log/supervisor/php-fpm.log
stderr_logfile=/var/log/supervisor/php-fpm.error.log
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx.error.log
Now the original issue I have is that my Laravel app can't write to storage folder. I could chmod 777 the folder recursively, and it works, but is not what I want.
So steps I took first is to chown -R nginx:nginx /var/www/* leaving permissions as is. This resolved nothing, still can't write.
Doing a ps aux revealed this:
PID USER TIME COMMAND
1 root 0:00 {supervisord} /usr/bin/python2 /usr/bin/supervisord --nodaemon --configuration /etc/supervisord.conf
8 root 0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.d/www.conf)
9 root 0:00 nginx: master process /usr/sbin/nginx -g daemon off;
10 nginx 0:00 nginx: worker process
11 nginx 0:00 nginx: worker process
12 nginx 0:00 nginx: worker process
13 nginx 0:00 nginx: worker process
14 nginx 0:00 {php-fpm7} php-fpm: pool www
15 nginx 0:00 {php-fpm7} php-fpm: pool www
So php-fpm is running as nginx user (I've changed it's original config to replace user nobody to nginx). This did nothing good, as with this settings instead of nobody user, request returns 502 error.
Nginx master process is running as root, and worker processes as nginx.
This is a tad confusing as I am not sure which user is my web server using here? Root or nginx? Does it take the user from supervisor, nginx master or nginx worker?
I've tried changing supervisor to start as nginx user, but that fails as supervisor needs root access to create pid.
Reverting supervisor to root and adding user=nginx to [program:nginx] section made supervisor not start nginx at all.
How can I do the permissions here the right way?
I think the best you can do , is to run both nginx and php-fpm as www-data:www-data
step one
add/edit this to your nginx.conf:
user www-data www-data;
step two
add/edit php-fpm.conf and set user and group to www-data more info here
I hope that will help you
Even after i stoped all docker containers and did docker system prune -a Docker is still downloading and executing tutum/php-apache by runing the command docker-compose up, here is my docker-compose.yml:
version: '2'
services:
postgres:
image: camptocamp/postgres
web:
image: nginx
ports:
- "8000:80"
volumes:
- '.:/usr/share/nginx/html
'
And here is runing containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3807234b989f camptocamp/postgres "docker-entrypoint.sā¦" 5 minutes ago Up 5 minutes 5432/tcp ferrybox_postgres_1
551acc487c9d tutum/apache-php "/run.sh" 5 minutes ago Up 5 minutes 80/tcp, 0.0.0.0:32786->8000/tcp ferrybox_web_1
docker system prune -a will remove all unused images , so assuming that you when executing this command - it is possible that tutum/apache-php image was used by the running-container and it was not created/started by the current docker-compose.yml file (may be docker-compose.yml file had this entry before).
docker#default:~$ docker system prune --help
Usage: docker system prune [OPTIONS]
Remove unused data
Options:
-a, --all Remove all unused images not just dangling ones
--filter filter Provide filter values (e.g. 'label=<key>=<value>')
-f, --force Do not prompt for confirmation
--volumes Prune volumes
docker#default:~$
Can you stop the container (use container-id or name) and remove it,
just to ensure if tutum/apache-php container was created+started again when you invoke docker-compose up ?
#>docker rm -f 3807234b989f
#>docker rm -f 551acc487c9d
#>docker system prune -a
#>docker-compose up
#>docker-compose ps
#>docker ps
Let me know if you get the same output as you were getting earlier.
On my single VPS host I've already an apache with websites. I want to keep it and have an docker with this nginx-proxy with subdomain. Later i will migrate everything in docker .
Apache run on port:80 , 443
nginx-proxy runs on port 81 using jwilder/nginx-proxy docker .
subdomain.domain.com maps to server IP : 109.xxx.xx.xx
Apache is serving content correctly .
nginx-proxy runs smoothly on port 81 .
docker run -d --name nginx-proxy -p 81:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
Then i run my sub domain container as suggested here
docker run -e VIRTUAL_HOST=crawling.domain.com -e VIRTUAL_PORT=8181 --volume /home/vps/crawling/crawling/:/var/www/html --detach --publish 8181:80 crawling
Now problem is when use http://subdomain.domain.com it redirects to server ip (109.xxx.xx.xx) home where some dummy index page is used .
Currently i can't change apache port as it will effect many serving content.
EDIT :
as #Tarun suggest i need to pass proxy from Apache to nginx docker . Any suggestion would be great.
I'm using docker and my container is build over php:5.6-fpm image from php official repo.
Is it somehow possible to restart/reload php-fpm from inside a container?
php-fpm is a process manager which supports the USER2 signal, which is used to reload the config file.
From inside the container:
kill -USR2 1
Outside:
docker exec -it <mycontainer> kill -USR2 1
Complete example:
docker run -d --name test123 php:7.1-fpm-alpine
docker exec -it test123 ps aux
docker exec -it test123 kill -USR2 1
docker exec -it test123 ps aux
You don't have to go inside the container
on your host
ps -ef|grep fpm // find master pid
kill -USR2 <master_pid>
This works for me:
If the command fpm restart fails run this inside the Docker container -> www#:
root#...:/var/www# **ps -ef|grep fpm**
www-data 160 1 0 10:02 ? 00:00:00 php-fpm: pool www
www-data 161 1 0 10:02 ? 00:00:00 php-fpm: pool www
root 1111 170 0 10:04 pts/0 00:00:00 grep --color=auto fpm
root#...:/var/www# **kill -USR2 170**
root#...:/home/user/Docker# **docker-compose stop**
Stopping docker_nginx_1 ... done
Stopping docker_oracle_1 ... done
root#...:/home/user/Docker# **docker-compose up -d**
Starting docker_oracle_1 ... done
Starting docker_nginx_1 ... done
root#...:/home/user/Docker# **docker-compose exec oracle bash**
root#...:/var/www# **/etc/init.d/php7.2-fpm restart**
* Restarting PHP 7.2 FastCGI Process Manager php-fpm7.2 **[ OK ]**
docker container kill --signal USR2 php_container_name
Details: https://docs.docker.com/engine/reference/commandline/container_kill/
You can also just restart the container..
sudo docker restart <container>
I have running the "FROM php:5.6-apache" container with my own php application. That works. But one part didn't.
My application can not use the network.
If i run manualy
docker run -t -i myapp ping 8.8.8.8 it
that works great. But if my app does it like
$ping = exec("ping -c 1 -s 64 -t 64 8.8.8.8");
then it doesen't.
Jan