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
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
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
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
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
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