Nginx Issue while deploying dockerized laravel to Digital Ocean

I am deploying Containerized Laravel to Digital Ocean using the bitbucket pipeline. I am pushing the PHP image to the docker hub and pulling it from there. Everything goes right but in the end, nginx starts to fail. However, I have tried to fix it but still have no luck. However, it works fine locally. I am sharing the code that I have used for server deployment. Any help will be appreciated.

Nginx Code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
server_tokens off;
chunked_transfer_encoding off;
gzip on;
gzip_types application/json;
gzip_min_length 1000;
include /etc/nginx/conf.d/*.conf;
}
</code>
<code>user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; server_tokens off; chunked_transfer_encoding off; gzip on; gzip_types application/json; gzip_min_length 1000; include /etc/nginx/conf.d/*.conf; } </code>
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    server_tokens off;
    chunked_transfer_encoding off;

    gzip on;
    gzip_types application/json;
    gzip_min_length 1000;

    include /etc/nginx/conf.d/*.conf;
}

Default.conf code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>server {
listen 80;
index index.php index.html;
root /var/www/public;
client_max_body_size 100M; # 413 Request Entity Too Large
location / {
root /var/www/public;
index index.html index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_read_timeout 3600;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
send_timeout 3600;
proxy_connect_timeout 3600;
proxy_read_timeout 3600;
proxy_send_timeout 3600;
}
}
</code>
<code>server { listen 80; index index.php index.html; root /var/www/public; client_max_body_size 100M; # 413 Request Entity Too Large location / { root /var/www/public; index index.html index.php; try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass php:9000; fastcgi_read_timeout 3600; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; send_timeout 3600; proxy_connect_timeout 3600; proxy_read_timeout 3600; proxy_send_timeout 3600; } } </code>
server {
  listen 80;
  index index.php index.html;
  root /var/www/public;

  client_max_body_size 100M; # 413 Request Entity Too Large

  location / {
    root /var/www/public;
    index  index.html index.php;
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ .php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_read_timeout 3600;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    send_timeout 3600;
    proxy_connect_timeout 3600;
    proxy_read_timeout    3600;
    proxy_send_timeout    3600;
  }
}

Bitbucket Pipeline

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>image: atlassian/default-image:latest
pipelines:
default:
- step:
name: Build and Push to Docker Hub
services:
- docker
script:
- docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
- docker build -t $DOCKER_HUB_USERNAME/php-app:latest -f docker/php/Dockerfile .
- docker push $DOCKER_HUB_USERNAME/php-app:latest
- step:
name: Deploy to DigitalOcean
deployment: production
script:
- pipe: atlassian/ssh-run:0.4.3
variables:
SSH_USER: $DO_SSH_USER
SERVER: $DO_SERVER
COMMAND: |
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
docker pull $DOCKER_HUB_USERNAME/php-app:latest
docker-compose -f docker-compose-dev.yml down &&
docker-compose -f docker-compose-dev.yml up -d
</code>
<code>image: atlassian/default-image:latest pipelines: default: - step: name: Build and Push to Docker Hub services: - docker script: - docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD - docker build -t $DOCKER_HUB_USERNAME/php-app:latest -f docker/php/Dockerfile . - docker push $DOCKER_HUB_USERNAME/php-app:latest - step: name: Deploy to DigitalOcean deployment: production script: - pipe: atlassian/ssh-run:0.4.3 variables: SSH_USER: $DO_SSH_USER SERVER: $DO_SERVER COMMAND: | docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD docker pull $DOCKER_HUB_USERNAME/php-app:latest docker-compose -f docker-compose-dev.yml down && docker-compose -f docker-compose-dev.yml up -d </code>
image: atlassian/default-image:latest

pipelines:
  default:
        - step:
            name: Build and Push to Docker Hub
            services:
              - docker
            script:
              - docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
              - docker build -t $DOCKER_HUB_USERNAME/php-app:latest -f docker/php/Dockerfile .
              - docker push $DOCKER_HUB_USERNAME/php-app:latest
        - step:
            name: Deploy to DigitalOcean
            deployment: production
            script:
              - pipe: atlassian/ssh-run:0.4.3
                variables:
                  SSH_USER: $DO_SSH_USER
                  SERVER: $DO_SERVER
                  COMMAND: |
                    docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
                    docker pull $DOCKER_HUB_USERNAME/php-app:latest
                    docker-compose -f docker-compose-dev.yml down &&
                    docker-compose -f docker-compose-dev.yml up -d

This is my server docker-compose-dev.yml script

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>services:
php:
image: sundarban123/php-app
ports:
- 5173:5173
volumes:
- .:/var/www:cached
nginx:
image: nginx
ports:
- 80:80
volumes:
- .:/var/www
- .docker/nginx/default.conf:/etc/nginx/conf.d
- .docker/nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- php
db:
image: mysql:8.1
ports:
- 3306:3306
volumes:
- .docker/db/data:/var/lib/mysql
- .docker/logs:/var/log/mysql
- .docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
- .docker/db/sql:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ****
MYSQL_USER: *****
MYSQL_PASSWORD: *****
</code>
<code>services: php: image: sundarban123/php-app ports: - 5173:5173 volumes: - .:/var/www:cached nginx: image: nginx ports: - 80:80 volumes: - .:/var/www - .docker/nginx/default.conf:/etc/nginx/conf.d - .docker/nginx/nginx.conf:/etc/nginx/nginx.conf depends_on: - php db: image: mysql:8.1 ports: - 3306:3306 volumes: - .docker/db/data:/var/lib/mysql - .docker/logs:/var/log/mysql - .docker/db/my.cnf:/etc/mysql/conf.d/my.cnf - .docker/db/sql:/docker-entrypoint-initdb.d environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: **** MYSQL_USER: ***** MYSQL_PASSWORD: ***** </code>
services:
  php:
    image: sundarban123/php-app
    ports:
      - 5173:5173
    volumes:
      - .:/var/www:cached
  nginx:
    image: nginx
    ports:
      - 80:80
    volumes:
      - .:/var/www
      - .docker/nginx/default.conf:/etc/nginx/conf.d
      - .docker/nginx/nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - php
  db:
    image: mysql:8.1
    ports:
      - 3306:3306
    volumes:
      - .docker/db/data:/var/lib/mysql
      - .docker/logs:/var/log/mysql
      - .docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
      - .docker/db/sql:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: ****
      MYSQL_USER: *****
      MYSQL_PASSWORD: *****

My folder structure

Error from Pipeline

Actual Error Message

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/tmp/docker/nginx/nginx.conf" to $DO_SSH_USERfs at "/etc/nginx/nginx.conf": mount /tmp/docker/nginx/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Connection to $DO_SERVER closed.
</code>
<code>Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/tmp/docker/nginx/nginx.conf" to $DO_SSH_USERfs at "/etc/nginx/nginx.conf": mount /tmp/docker/nginx/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type Connection to $DO_SERVER closed. </code>
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/tmp/docker/nginx/nginx.conf" to $DO_SSH_USERfs at "/etc/nginx/nginx.conf": mount /tmp/docker/nginx/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Connection to $DO_SERVER closed.

Any help is appreciated. Thank you

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật