Browse Source

chore: fixed an issue that occurred when nginx did not have permissions on the 'php-fpm8.sock' file

Junior L. Botelho (JLB) 2 years ago
parent
commit
8b2b8af183
5 changed files with 17 additions and 6 deletions
  1. 1 3
      Dockerfile
  2. 6 1
      docker/entrypoint.sh
  3. 2 0
      docker/php/prepare.sh
  4. 2 0
      docker/server/nginx.dockerfile
  5. 6 2
      docker/server/prepare.sh

+ 1 - 3
Dockerfile

@@ -36,10 +36,8 @@ RUN   chmod u+x "${DOCKER_SCRIPTS}/php/prepare.sh" &&\
 RUN   apk add openrc abuild-rootbld --no-cache
 
 # The following lines import all Dockerfiles from other folders so that they can be built together in the final build
-INCLUDE+ docker/php/php.dockerfile
 INCLUDE+ docker/server/nginx.dockerfile
-
-RUN   apk del -r abuild-rootbld
+INCLUDE+ docker/php/php.dockerfile
 
 EXPOSE ${NGINX_PORT}
 

+ 6 - 1
docker/entrypoint.sh

@@ -1,6 +1,11 @@
 #!/bin/sh
 
+# Due to an issue with Docker's 'CMD' directive, the following scripts are not executing as expected.
+# This workaround has been implemented to resolve the issue for now
+sh "docker/php/prepare.sh"
+sh "docker/server/prepare.sh"
+
 service php-fpm8 start
 service nginx start
 
-exec nginx -g daemon off;
+exec nginx -g "daemon off;"

+ 2 - 0
docker/php/prepare.sh

@@ -1,5 +1,7 @@
 #!/bin/sh
 
+echo "[PREPARE] docker/server/prepare.sh'"
+
 # Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
 source "docker/attributes.sh"
 

+ 2 - 0
docker/server/nginx.dockerfile

@@ -1,3 +1,5 @@
+# Install Nginx with FastCGI enabled, optimizing its performance for serving content
 RUN apk add nginx
 
+# After executing the 'docker run' command, run the 'prepare.sh' script
 CMD [ "/bin/sh", "-c", "docker/server/prepare.sh" ]

+ 6 - 2
docker/server/prepare.sh

@@ -1,13 +1,17 @@
 #!/bin/sh
 
+echo "[PREPARE] docker/server/prepare.sh'"
+
 # Load all environment variables from 'attributes.sh' using the command 'source /path/attributes.sh'
 source "docker/attributes.sh"
 
 # This condition creates the Unix socket if 'php-fpm8.sock' does not already exist.
 # This fixes an issue where Nginx starts but does not serve content
 if [ ! -d "/run/php8" ] || [ ! -S "/run/php8/php-fpm8.sock" ]; then
-    mkdir /run/php8
-    touch /run/php8/php-fpm8.sock
+    mkdir "/run/php8"
+    touch "/run/php8/php-fpm8.sock"
+    chmod 0660 "/run/php8/php-fpm8.sock"
+    chown nginx:nginx "/run/php8/php-fpm8.sock"
 fi
 
 export OPEN_SEARCH_HOST_FOR_NGINX="$(echo "${OPEN_SEARCH_HOST}" | cut -d "/" -f 3 | cut -d ":" -f 1)"