What is wrong with my Laravel docker compose File? - php

Can anybody help me with the following? I have a docker-compose file with the following services PHP, Mysql, Redis, and Nginx. The docker-compose file builds without any issues but when I try the URL its not working. The file is down below
version: '3.8'
services:
php:
build: ./docker-compose/php-81/build
image: php-81
container_name: cumax-php-db
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
- ./docker-files/storage/logs/php:/var/www/default/logs
networks:
- onboarding
db:
image: mysql:8.0
container_name: cumax-mysql-db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql8.0/storage:/var/lib/mysql
networks:
- onboarding
nginx:
image: nginx:1.17-alpine
container_name: cumax-nginx
restart: unless-stopped
ports:
- "8070:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx/conf.d:/etc/nginx/conf.d
networks:
- onboarding
redis:
image: "redis:alpine"
ports:
- "6379:6379"
networks:
- onboarding
networks:
onboarding:

On php you don't publish the port.
On the Nginx you only publish to port 8070 on the host.
What is the URL you are using? It should be http://< host >:8070/
And then the nginx should proxy onwards to php.

Related

environment problem in yml file for docker

i make an error on the point youmas:
environment:
XDEBUG_CONFIG: remote_host=172.17.0.1 remote_port=9000 remote_enable=1
networks:
- youmas
but i dont know how to fix them
version: "3"
services:
#PHP
youmas-app:
build:
context: .
dockerfile: Dockerfile
args:
- WITH_XDEBUG=true
image: youmas-app
container_name: youmas-app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS:
dev
# If you down want to use xDebug, set remote_enable=0
PHP_IDE_CONFIG: "serverName=Docker"
XDEBUG_CONFIG: remote_host=192.168.178.33 remote_port=9001
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/production/php/local.ini:/usr/local/etc/php/conf.d/local.ini
youmas:
environment:
XDEBUG_CONFIG: remote_host=172.17.0.1 remote_port=9000 remote_enable=1
networks:
- youmas
#Nginx
youmas-webserver:
build:
context: .
dockerfile: "./docker/production/nginx/Dockerfile"
container_name: youmas-webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./docker/production/nginx/conf.d/:/etc/nginx/conf.d/
- ./docker/production/certbot/conf:/etc/letsencrypt
- ./docker/production/certbot/www:/var/www/certbot
networks:
- youmas
command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
# Certbot SSL
certbot:
image: certbot/certbot
volumes:
- ./docker/production/certbot/conf:/etc/letsencrypt
- ./docker/production/certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
#MySQL
youmas-database:
image: mysql:5.7.22
container_name: youmas-database
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: youmas
MYSQL_ROOT_PASSWORD: K4#|ahdpof8##!~
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./docker/production/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- youmas
#PHP My Admin
youmas-phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "7000:80"
links:
- youmas-database:youmas-database
environment:
MYSQL_USER: root
MYSQL_PASSWORD: codeverze
MYSQL_ROOT_PASSWORD: codeverze
networks:
- youmas
#Networks
networks:
youmas:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
any solution?
Your Syntax is wrong,
Replace the environment section to look like this :
youmas-app:
build:
context: .
...
...
...
environment:
- 'SERVICE_NAME=app'
- 'SERVICE_TAGS=dev'
...
...

Why do extra folders get created in laravel public folder when i use docker as a dev environment and how do i stop it

In the image above the extra folders in the public folder only appears when ever i set up a dev environment with docker, the logs go to these folders instead of the /storage/logs/.
Another thing i experience when i use docker dev environment is i always have to reload cache (artisan optimize) before my config or route changes can be applied in the container.
THIS IS MY Docker-Compose FILE
version: "3"
networks:
laravel:
services:
nginx:
container_name: testproj-nginx
image: nginx:stable-alpine
ports:
- "2022:80"
volumes:
- ./:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:8
container_name: testproj-mysql
restart: unless-stopped
tty: true
ports:
- "2306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: testproj
MYSQL_USER: root_user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build: ./
container_name: testproj-php
volumes:
- ./:/var/www/html
networks:
- laravel
mailhog:
image: "mailhog/mailhog:latest"
container_name: testproj-mailhog
ports:
- "${FORWARD_MAILHOG_PORT:-2025}:1025"
- "${FORWARD_MAILHOG_DASHBOARD_PORT:-9025}:8025"
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: testproj-pma
links:
- mysql
environment:
PMA_HOST: testproj-mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8083:80
networks:
- laravel
depends_on:
- php
- mysql
# ngrok:
# image: wernight/ngrok:latest
# container_name: testproj-ngrok
# ports:
# - 4041:4040
# environment:
# NGROK_AUTH: ${NGROK_AUTH_KEY}
# NGROK_REGION: eu
# NGROK_PROTOCOL: http
# NGROK_PORT: testproj-nginx:80
# networks:
# - laravel
# depends_on:
# - nginx

How to mirror production server using docker-compose for Wordpress

I have the following docker-compose file for running a Wordpress website.
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
- ./mysql-dump:/docker-entrypoint-initdb.d
restart: always
environment:
MYSQL_ROOT_PASSWORD: admin123
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '8081:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: admin123
networks:
- wpsite
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8001:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
networks:
- wpsite
volumes:
- "../../blogs:/var/www/html"
- "../../blogs/plugins:/var/www/html/wp-content/plugins"
networks:
wpsite:
volumes:
db_data: {}
Here I am using the official wordpress:latest image, but my production server has a different configuration. I would like to use the same PHP version and other configurations. How can I do it ?

Is it possible to use the same docker container for multiple websites

until a new version of php or mysql comes out I generally always use the same setup, so at the moment I create 3 containers for every site I create:-
Site 1:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site1
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site1
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site1
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site1
networks:
site1:
volumes:
db_data:
Site 2:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site2
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site2
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site2
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site2
networks:
site2:
volumes:
db_data:
They are identical except for the network but this means I have 6 containers when really I only need 3. Is it possible to tell site 2 to use the services that site 1 created or does this go against the whole point of docker?
So what I would like is to change:-
Site 1 uses php, mysql and phpmyadmin. Site 2 uses php1, mysql1, phpmyadmin1.
to:
both site 1 and site 2 using the same container's but having their own database:-
Site 1 uses php, mysql (database site1) and phpmyadmin. Site 2 uses php, mysql (database site2) and phpmyadmin

How to make API calls within docker environment?

I am building an app wrapped in docker, that consist of PHP backend ("API") and NODE frontend, they are united by NGINX, where php app is served by the means of php-fpm and my node app is served by the reverse proxy. NGINX exposes phpMyAdmin app (phpmyadmin.test) and "API" (api.php.test) for dev purposes and NODE api (nodeapp.test).
NODE apps SSR ("Server-Side Rendering") needs to fetch some data from an API within docker the network, and because domains such as api.php.test can't be recognized from within docker I have to make calls to NGINX container which serves 3 different domains mentioned above, so I either need to fake 'HOST' header to get appropriate response from an API via NGINX which leads problems. Such as: Refused to set unsafe header "Host", Error: unable to verify the first certificate in nodejs etc.
Do I have to spin up Nginx container for each endpoint to avoid these issues? Or is there a better way to go around this?
Here is an example of my docker-compose.yml to give you a better idea of what happens in my app.
version: "3.7"
services:
workspace:
build:
context: workspace
args:
WORKSPACE_USER: ${WORKSPACE_USER}
volumes:
- api:/var/www/api
- site:/var/www/site
ports:
- "2222:22"
environment:
S3_KEY: ${S3_KEY}
S3_SECRET: ${S3_SECRET}
S3_BUCKET: ${S3_BUCKET}
DB_CONNECTION: ${DB_CONNECTION}
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MEDIA_LIBRARY_ENDPOINT_TYPE: ${MEDIA_LIBRARY_ENDPOINT_TYPE}
MEDIA_LIBRARY_IMAGE_SERVICE: ${MEDIA_LIBRARY_IMAGE_SERVICE}
tty: true
php-fpm:
build:
context: ./php-fpm
depends_on:
- nodejs
volumes:
- api:/var/www/api
- ./certs:/certs
environment:
S3_KEY: ${S3_KEY}
S3_SECRET: ${S3_SECRET}
S3_BUCKET: ${S3_BUCKET}
DB_CONNECTION: ${DB_CONNECTION}
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MEDIA_LIBRARY_ENDPOINT_TYPE: ${MEDIA_LIBRARY_ENDPOINT_TYPE}
MEDIA_LIBRARY_IMAGE_SERVICE: ${MEDIA_LIBRARY_IMAGE_SERVICE}
nodejs:
build:
context: ./nodejs
args:
NODEJS_SITE_PATH: ${NODEJS_SITE_PATH}
NODEJS_VER: ${NODEJS_VER}
volumes:
- site:${NODEJS_SITE_PATH}
- ./certs:/certs
environment:
NODEJS_ENV: ${NODEJS_ENV}
ports:
- 3000:3000
- 3001:3001
nginx:
build:
context: nginx
depends_on:
- php-fpm
- mariadb
restart: always
volumes:
- api:/var/www/api
- site:/var/www/site
- ./nginx/global:/etc/nginx/global
- ./nginx/sites:/etc/nginx/sites-available
- ./nginx/logs:/var/log/nginx
- ./certs:/certs
ports:
- 80:80
- 443:443
mariadb:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- db:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- mariadb
restart: always
environment:
PMA_HOST: ${MYSQL_HOST}
PMA_USER: root
PMA_PASSWORD: ${MYSQL_ROOT_PASSWORD}
UPLOAD_LIMIT: 2048M
volumes:
phpmyadmin:
db:
site:
external: true
api:
external: true

Categories