Docker containerization #353
-
Good afternoon! What if laravel api and nuxt application are in different containers, but I want to use cookie-based authorization? Setting |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Hey @Jonston! This can be solved by naming you Laravel app the same way as domain would be. For example, Laravel container name - Then you can setup an entry in your In this case, CSR requests will go to You can check more details in the following discussions: |
Beta Was this translation helpful? Give feedback.
-
I'm having difficulty setting up nginx. The server and client seem to be configured normally, but communication between the Nuxt -> Laravel container is problematic. Could you help me? services:
laravel:
build:
context: .
dockerfile: Dockerfile
container_name: api.events.local
restart: unless-stopped
working_dir: /var/www/html
volumes:
- .:/var/www/html
networks:
- laravel-network
- shared-network
depends_on:
- mysql
env_file:
- .env
mysql:
image: mysql:8.0
container_name: mysql
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:
- mysql-data:/var/lib/mysql
networks:
- laravel-network
ports:
- "3306:3306"
networks:
laravel-network:
driver: bridge
shared-network:
external: true
volumes:
mysql-data:
driver: local Frontend docker-compose.yml services:
nuxt:
build: .
container_name: events
restart: unless-stopped
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
command: npm run dev
networks:
- nuxt-network
- shared-network
networks:
nuxt-network:
driver: bridge
shared-network:
external: true nginx default.conf
Буду очень признателен за помощь |
Beta Was this translation helpful? Give feedback.
-
You can make it work even without Nginx if Laravel and Nuxt containers are working as long-running apps on their own. However, if you want to use Nginx, make sure it is connected to the same network. I'm transferring this issue into a discussion, where you can ask further questions. The best option would be to provide a minimal repro, which configuration I can help with. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer. Can you show an example without nginx? |
Beta Was this translation helpful? Give feedback.
-
@manchenkoff thanx a lot man. My Englesh no so strong? but i try explain Thanks a lot for your plugin it have very usefull staf. Your i undestand your proposition. I am rum laravel app as a nosistanse docker imag and it work. I glad for that. Thank to a Gods! But share mu trying to keep alive internet. services:
nuxt:
build: .
container_name: events.local
restart: unless-stopped
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
command: npm run dev
networks:
- nuxt-network
- shared-network
networks:
nuxt-network:
driver: bridge
shared-network:
external: true Here laravel api docker-compose.yml config services:
api.events.local:
build:
context: './vendor/laravel/sail/runtimes/8.4'
dockerfile: Dockerfile
args:
WWWGROUP: '${WWW_GROUP}'
image: 'sail-8.4/app'
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWW_USER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}'
volumes:
- '.:/var/www/html'
networks:
- sail
- shared-network
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
shared-network:
external: true
volumes:
sail-mysql:
driver: local Do its works for me! services:
# Nginx сервис
nginx:
build:
context: ./docker/nginx
container_name: laravel_nginx
ports:
- "80:80"
volumes:
- ./:/var/www/html
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/nginx.conf
depends_on:
- php
networks:
- laravel-network
- shared-network |
Beta Was this translation helpful? Give feedback.
Hey @Jonston! This can be solved by naming you Laravel app the same way as domain would be. For example, Laravel container name -
api.myapp.test
.Then you can setup an entry in your
/etc/hosts
(depends on your OS), to makeapi.myapp.test
accessible from the web browser.In this case, CSR requests will go to
api.myapp.test
-> resolved to docker -> passed into Laravel containerFor SSR, requests will go directly to the container named
api.myapp.test
(they should be in the same network)You can check more details in the following discussions: