How to run queue work on Laravel with docker? - php

I create an docker setup on my Laravel project using sail.
În my project I use jobs and I want when I run docker-compose up to start command php artisan queue:work. In my docker-compose.yml I defined an service php-queue like this:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./docker/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
php-queue:
restart: always
image: sail-8.0/app:latest
command: 'php artisan queue:work'
volumes:
- '.:/var/www/html'
mysql:
image: 'mysql:5.7'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
when I run docker-conpose up in docker desktop it shows this error:
error: failed switching to "php": unable to find user php: no matching entries in passwd file
what I missed?

change command: 'php artisan queue:work' to command: ['/bin/sh', '-c', 'php artisan queue:work' thats should work
Also this could help you :)
https://laravel.com/docs/8.x/sail#executing-sail-commands
Running Artisan commands locally...
php artisan queue:work
Running Artisan commands within Laravel Sail...
sail artisan queue:work

Related

Failed UDP connection in Docker container

I am working on a laravel php application which seemed to running fine until I stopped working for the day by running the docker-compose down command. When I got back to working again by starting the container docker-compose up -d, the container started throwing a failed connecting to udp error. Below is the error I am getting
In my logs I can see some message
[2022-09-07 07:25:09] local.ERROR: Failed connecting to udp://: (0: Failed to parse address ":") {"exception":"[object] (UnexpectedValueException(code: 0): Failed connecting to udp://: (0: Failed to parse address ":") at /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/SocketHandler.php:313)
Because of the error php exits and I can do practically nothing with the app at this point. Does anyone know how I can deal with the issue and get php state back to running?
Below is my docker file
# For more information: https://laravel.com/docs/sail
version: '3'
services:
gateway:
build:
context: services/vendor/laravel/sail/runtimes/7.4
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-7.4/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '8000:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- './gateway:/var/www/html'
networks:
- sail
depends_on:
- db1
- redis
- mailhog
services:
build:
context: servvices/vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '8002:80'
- '${VITE_PORT:-5175}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- './loans:/var/www/html'
networks:
- sail
depends_on:
- gateway
- db2
# gateway db
db1:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${GATEWAY_DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${GATEWAY_DB_DATABASE}'
MYSQL_USER: '${GATEWAY_DB_USERNAME}'
MYSQL_PASSWORD: '${GATEWAY_DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'spg_db:/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${GATEWAY_DB_PASSWORD}"]
retries: 3
timeout: 5s
# service db
db2:
image: 'mysql/mysql-server:8.0'
ports:
- '3308:3306'
environment:
MYSQL_ROOT_PASSWORD: '${SERVICE_DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${SERVICE_DB_DATABASE}'
MYSQL_USER: '${SERVICE_DB_USERNAME}'
MYSQL_PASSWORD: '${SERVICE_DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'spl_db:/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${SERVICE_DB_PASSWORD}"]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT}:6379'
volumes:
- 'redis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
volumes:
db1:
driver: local
db2:
driver: local
redis:
driver: local

Why won't Laravel Sail allow me to connect to the DB

Anyone familiar with using Laravel Sail? I can't find for the life of me figure out why I can't connect to myDb using the credentials provided when installing Sail.
My DB credentials in the .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3307
DB_DATABASE=myDb
DB_USERNAME=sail
DB_PASSWORD=password
I've tried:
switching DB_HOST back and forth from 127.0.0.1 to localhost
but still getting that same error.
switching DB_HOST to mysql but still getting that same error.
running docker ps -a | grep mysql and the output is: 8b1ef6c28b4e mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 4 minutes ago Up 4 minutes (healthy) 3306/tcp, 33060-33061/tcp, 0.0.0.0:3307->3307/tcp myApp-mysql-1 so no issues with the connection per the output.
running ./vendor/bin/sail sail mysql -u root -p and it allowed me access to mysql on the CLI
almost everything else out there to no avail
Not sure what else to do. How can I connect to my db in a GUI?
docker-compose.yml file:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${HMR_PORT:-8080}:8080'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3307}:3307'
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
volumes:
sail-mysql:
driver: local
Change the DB_HOST variable to mysql as the following:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3307
DB_DATABASE=myDb
DB_USERNAME=sail
DB_PASSWORD=password

net::ERR_CONNECTION_REFUSED using Laravel 9 with Laravel Sail on PHP 8.1

I am building an app with Laravel, Vue 3 and Inertia.js.
I tried to set up a development server with Laravel Sail.
I have docker running in my machine and all the containers are running, the problem is that whenever I access localhost it throws me these errors even though after I run the script sail npm run hot:
GET http://localhost:3000/browser-sync/browser-sync-client.js net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/css/app.css net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/css/all.min.css net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/js/manifest.js net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/js/vendor.js net::ERR_CONNECTION_REFUSED
GET http://localhost:8080/js/app.js net::ERR_CONNECTION_REFUSED
My docker-compose.yml file contains the following:
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
- meilisearch
- selenium
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
meilisearch:
image: 'getmeili/meilisearch:latest'
ports:
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
volumes:
- 'sailmeilisearch:/data.ms'
networks:
- sail
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--spider", "http://localhost:7700/health"]
retries: 3
timeout: 5s
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
selenium:
image: 'selenium/standalone-chrome'
volumes:
- '/dev/shm:/dev/shm'
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
sailmeilisearch:
driver: local
I am on a Windows 11 machine using WSL2 and Ubuntu-20.04

Laravel sail problem with migrations, the console does not return anything

I have a problem with laravel sail. My problem is I can't migrate models. I used the command vendor/bin/sail artisan migrate but the console gives me nothing, no error, It also did not create any tables in the database. When I went to the project website and tried to create a new user, I could click the migration button and everything worked. sail node --version or similar commands also do not return anything
# For more information: https://laravel.com/docs/sail
version: '3'
services:
web:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '80:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql:8.0'
platform: linux/amd64
container_name: clinic_db
restart: unless-stopped
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping"]
phpmyadmin:
image: 'phpmyadmin:latest'
ports:
- 8080:80
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
links:
- "mysql:db"
depends_on:
- mysql
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
Works on macbook pro m1. Can anyone fix this error?
I ran into this in my project. I had to add this to my .env
APP_SERVICE=laravel
where "laravel" was the the name of the container for the app. so in your case it would be
APP_SERVICE=web
My particular project that had the issue was an old laravel 5.7 project that we recently updated to laravel 8.x. I didn't run into this issue on newer installs. Maybe more recent versions of laravel do not need this extra .env variable?

how to run command in docker-compose.yml file?

i have laravel project and i want to create docker for it
and i want to automation it
i want to run this commends:
{
php artisan key:generate
php artisan migrate
php artisan queue:work --daemon
}
and its my docker-compose.yml file
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: xxxx/lumen:Library
container_name: Library
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: LibraryWebserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: Librarydb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: library
MYSQL_ROOT_PASSWORD: Library!23
MYSQL_USER: root
MYSQL_PASSWORD: Library!23
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- app-network
volumes:
- dbdata:/var/lib/mysql
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
i try to use command: php artisan migrate and its do nothing
and also use
command: bash -c "php artisan migrate"
command: 'php artisan migrate'
You can use a command like the below example. It will run the command once the container is up and running.
version: "3.0"
services:
app:
image: busybox
command: top
networks:
app_net:
link_local_ips:
- 57.123.22.11

Categories