如何通过unix套接字在Kubernetes中运行PHP?

我在Google容器引擎中有nginx和php-fpm容器,我想通过unix套接字而不是networking来运行它。

我还拥有Google SQL代理容器,它使用空卷通过放置在与其他容器共享的卷上的套接字提供与Google SQL数据库的连接。 所以我想为PHP使用相同的方法,但它不工作。

我有emptyDirtypes的空量挂载到php和nginx容器。 卷被安装,我可以在两个容器中看到它。 但是,如果我尝试使用nginx我会得到(套接字)文件没有在日志中find。

我也已经将www-data(与php容器中的uid相同)用户添加到nginx容器中,并将其设置在nginx conf中,但没有帮助。

Google SQL代理在某些方面是特殊的,我必须使用PHP的networking,或者我在这里错过了一些东西?

我设法得到了你所描述的方法。 我在deployment使用了emptyDir ,所以共享/sock文件夹被挂载到nginx和fpm:

  - name: fpm ... volumeMounts: - name: php-socket mountPath: /sock ... - name: nginx ... volumeMounts: - name: php-socket mountPath: /sock ... volumes: - name: php-socket emptyDir: {} 

我发现这篇文章对实际的nginx和fpmconfiguration很有帮助: https : //medium.com/@shrikeh/setting-up-nginx-and-php-fpm-in-docker-with-unix-sockets-6fdfbdc19f91

我碰到的障碍是我的php-fpm zz-docker.conf容器configuration文件,名为zz-docker.conf ,其中包含listen = [::]:9000 。 由于该文件的名称是字母高,它是clobbering我的其他configuration文件,停止unix套接字通信工作(即listen = /sock/php.sock )。 我在Dockerfile使用这个删除了问题行:

 sed -i -e '/listen/d' /usr/local/etc/php-fpm.d/zz-docker.conf