Name or service not known [tcp://redis:6379] change REDIS_HOST value still does'nt work - laravel

Need a help! My code was run on Docker and get problem with Redis.
I've checked on server the Redis is running.
I also try change in .env file REDIS_HOST=redis --> REDIS_HOST=localhost and REDIS_HOST=127.0.0.1 but does'nt work anymore!
REDIS_HOST=redis
php_network_getaddresses: getaddrinfo failed: Name or service not known [tcp://redis:6379]
REDIS_HOST=127.0.0.1 or REDIS_HOST=localhost
Connection refused [tcp://127.0.0.1:6379]
.env file
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
docker ps | grep redis
365ba9ede8e0 redis "docker-entrypoint.s…" 7 hours ago Up 7 hours 0.0.0.0:6379->6379/tcp redis
3e94135b4c83 redis:alpine "docker-entrypoint.s…" 8 hours ago Up 5 hours 6379/tcp ms-worker_redis_1
69d8708931e6 redis:alpine "docker-entrypoint.s…" 8 hours ago Up 8 hours 6379/tcp ma-worker-redis-service
810c182d403d redis:alpine "docker-entrypoint.s…" 8 hours ago Up 8 hours 6379/tcp ma-redis-service

had the same problem. It turned out that it was necessary to add radish to the application network
redis:
image: redis
restart: unless-stopped
ports:
- '6379:6379'
command: redis-server --save 20 1 --loglevel warning --requirepass ${REDIS_KEY}
volumes:
- redis:/data
networks:
- web

Related

How to dockerize vue3 laravel9 application?

I am developping a vue3 laravel9 SPA.
The app is presently running in dev and in production on a web hosting.
I would like to distribute it without the need of a web hosting as a dockerized application but I do not know docker that much.
I base my approach on this example : https://github.com/AveryHowell/docker-laravel-vue
I just copied from the example to my app
laravel/nginx (folder)
laravel/docker-compose.yml (file)
laravel/laravel.dockerfile (file)
vue/nginx.conf (file)
vue/vue.dockerfile (file)
The changes I made to this example are very limited.
First I changed the version of mysql in laravel/docker-compose.yml to mariadb:10.3.37
#Mysql DB
mysql:
image: mariadb:10.3.37
container_name: db
restart: unless-stopped
tty: true
ports:
- "33061:3306"
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
volumes:
- ../mysql:/mysql
networks:
- app-network
This version is the one I presently use and avoid some trouble with default values in json columns.
Secondly I changed the database config and some urls in .env
APP_NAME='my application'
APP_ENV=local
APP_KEY=base64:Wh2GGnDZ6YLEjNghheIX4qL+6P9lHuS8sO03L/pCufA=
APP_DEBUG=true
APP_URL=http://localhost
APP_API_URL=http://localhost/api/
APP_API_DEV_URL=http://localhost:8080/
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=secret
DB_ROOT_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
SESSION_DOMAIN=.localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8080
SPA_URL=http://localhost:8080
After that I used these commands
docker-compose up -d
docker-compose exec laravel composer update
docker-compose exec laravel composer install
docker-compose exec laravel composer dump-autoload
docker-compose exec laravel php artisan key:generate
docker-compose exec laravel php artisan config:cache
docker-compose exec laravel php artisan migrate:fresh
I had the tables created in mariadb
but when I visited localhost:8080 as said in the example, I got this message
The connection was reset
The connection to the server was reset while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer’s network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web.
What is wrong?
EDIT AFTER FIRST COMMENT
[jaaf#localhost laravel]$ docker container ls --filter label=com.docker.compose.project
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5719d4b36179 laravel-webserver "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp webserver
9b88d442636c laravel-vue "docker-entrypoint.s…" 44 minutes ago Restarting (1) 51 seconds ago vue
37743ac9307f laravel "docker-php-entrypoi…" 44 minutes ago Up 44 minutes 9000/tcp laravel
1cf764c56ad0 mariadb:10.3.37 "docker-entrypoint.s…" 44 minutes ago Up 44 minutes 0.0.0.0:33061->3306/tcp, :::33061->3306/tcp db
[jaaf#localhost laravel]$

Airflow doesn't work on localhost

I have tried to start Apache Airflow UI on my local machine (Windows 11) but have failed so far. Here are the list of works that I have done so far.
The contents of the 'docker-compose-LocalExecutor.yml' file are as follows:
version: '3.7'
services:
postgres:
image: postgres:9.6
environment:
- POSTGRES_USER=airflow
- POSTGRES_PASSWORD=airflow
- POSTGRES_DB=airflow
logging:
options:
max-size: 10m
max-file: "3"
webserver:
image: puckel/docker-airflow:1.10.9
restart: always
depends_on:
- postgres
environment:
- LOAD_EX=n
- EXECUTOR=Local
logging:
options:
max-size: 10m
max-file: "3"
volumes:
- ./dags:/usr/local/airflow/dags
# - ./plugins:/usr/local/airflow/plugins
ports:
- "8080:8080"
command: webserver
healthcheck:
test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
interval: 30s
timeout: 30s
retries: 3
redis:
image: redis
Compose Airflow container:
> cd C:\docker-airflow-master
> docker-compose -f docker-compose-LocalExecutor.yml up -d
Container docker-airflow-master-redis-1 Created
Container docker-airflow-master-postgres-1 Created
Container docker-airflow-master-webserver-1 Running
Container docker-airflow-master-redis-1 Starting
Container docker-airflow-master-postgres-1 Starting
Container docker-airflow-master-redis-1 Started
Container docker-airflow-master-postgres-1 Started
Check which containers are up and running:
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
74ac4cd4fafb puckel/docker-airflow:1.10.9 "/entrypoint.sh webs…" 2 days ago Up 40 minutes (healthy) 5555/tcp, 8793/tcp, 0.0.0.0:8080->8080/tcp docker-airflow-master-webserver-1
1acef40c382a postgres:9.6 "docker-entrypoint.s…" 2 days ago Up 3 minutes 5432/tcp docker-airflow-master-postgres-1
e7adfadd1c38 redis "docker-entrypoint.s…" 2 days ago Up 3
minutes 6379/tcp docker-airflow-master-redis-1
Check network connections:
> netstat
Proto Local Address Foreign Address State
TCP [::1]:8080 LAPTOP-0FSNTPS1:63790 TIME_WAIT
TCP [::1]:8080 LAPTOP-0FSNTPS1:63791 TIME_WAIT
TCP [::1]:8080 LAPTOP-0FSNTPS1:63792 TIME_WAIT
Open browser on address localhost:8080:
What could be wrong that it doesn't work?
Have you tried with the latest official docker compose file? It worked fine for me.

Laravel running inside docker successfully but unable to see anything in the browser?

Have been following this tutorial making a few changes when needed: https://medium.com/#pierangelo1982/dockerize-an-existing-laravel-application-with-docker-compose-a45eb7956cbd
After running docker-composer build and docker-composer up all the migrations run successfully and I get a message saying the app is running on http://0.0.0.0:8000 Hover that url or the one specified in the tutorial show nothing.
Here is my docker file
FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181
my docker-compose.yaml file
version: '2'
services:
app:
build: .
ports:
- '8009:8000'
volumes:
- .:/app
env_file: .env
working_dir: /app
command: bash -c 'composer install && php artisan migrate && php artisan serve --host 0.0.0.0'
depends_on:
- db
links:
- db
db:
image: 'mysql:5.7'
environment:
- MYSQL_ROOT_PASSWORD=1
- MYSQL_DATABASE=posts
- MYSQL_PASSWORD=1
volumes:
- ./data/:/var/lib/mysql
ports:
- '3306:3306'
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8090:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: 1
and my .env file
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:oD3DGqKdE7ne91FGu7YJzAJo721v56uVjAZGRGT6VNk=
APP_DEBUG=true
APP_URL=http://posts.test
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=posts
DB_USERNAME=root
DB_PASSWORD=1
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Not really sure what is happening at this point since it seems everything is running fine but then I see nothing on the specified port.
Helloy, I think you should check your port forwarding config. Inside container you start web server with command
CMD php artisan serve --host=0.0.0.0 --port=8181
And then I don't see where in you docker-compose.yaml you forwarded this inner port 8181 to external machine host port 8000

Laravel Sail SQL Connection timed out

I just started using Laravel Sail, but Laravel can't connect to the MySQL server. Even Artisan in the container gives Connection timed out. I can connect from MySQL Workbench on my host machine.
My .env file has been updated for use with sail:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
Laravel sail does not come with phpMyAdmin to visualize your database. so, you need to go with one of these:
add phpMyAdmin to your docker-compose.yml file manually.
services:
...
phpmyadmin:
image: phpmyadmin
restart: always
container_name: phpmyadmin
depends_on:
- mysql
ports:
- 8080:80
environment:
PMA_HOST: mysql
MYSQL_USERNAME: "${DB_USERNAME}"
MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
...
volumes:
...
phpmyadmin:
driver: local
restart your project again.
sail up -d
sail now will download phpMyAdmin image to your docker container where you
will able to view database on port:8080 [http://localhost:8080/].
use a graphical database management application like TablePlus as mentioned in sail documentation.
I recently ran across this issue too, when upgrading an old Laravel project from using homestead to sail. As per the docs you need to set DB_HOST=mysql in your .env file so that your application container can communicate with the MySQL container.
You must write in "DB_HOST" are domain or ip
DB_HOST=1.2.3.4
or
DB_HOST=example.com

Problem to make a cluster with laravel and docker swarm using laradock

I recently started with docker and I have been following this steps to make a cluster with laradock
https://github.com/jarnovanleeuwen/laravel-dock
first I create with docker-machine 2 nodes, one manager and the other a worker
then with this comand I set the manager node as the leader
docker swarm init --advertise-addr 192.168.99.100
I add the other node as a worker with
docker swarm join
After I access the manager node with docker-machine ssh manager and create a service
docker service create --name registry --publish published=5000,target=5000 registry:2
I leave the virtual machine with exit and cd into the folder laravel-dock, then I up the containers to create the images with
./dock up
then I set it down
./dock down
I build the image with
./dock build
Then i push it into the service I created with
./dock push
The push refers to repository [192.168.99.100:5000/registry]
Get https://192.168.99.100:5000/v2/: http: server gave HTTP response to HTTPS client
With this I try to deploy the stack with
./dock deploy
Are you sure you want to deploy [192.168.99.100:5000/registry:web] to [docker#192.168.99.100]? (y/N) y
Uploading deployment configuration...The authenticity of host '192.168.99.100 (192.168.99.100)' can't be established.
ECDSA key fingerprint is SHA256:r1F+7kuet+grlysNruBECAmYpRVVlvORYhAR4ipNFco.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.99.100' (ECDSA) to the list of known hosts.
docker#192.168.99.100's password:
docker#192.168.99.100's password:
OK
docker#192.168.99.100's password:
./dock-swarm: line 4: .env: No such file or directory
it request the password for the machine that is "tcuser" and come with this error ".env: No such file or directory", so I manually copy the .env to this folder created in the manager node with
docker-machine scp -r .env manager:/home/docker/laraveldock
I try to deploy again and have this error
sudo ./dock deploy
Are you sure you want to deploy [192.168.99.100:5000/registry:web] to [docker#192.168.99.100]? (y/N) y
Uploading deployment configuration...docker#192.168.99.100's password:
docker#192.168.99.100's password:
OK
docker#192.168.99.100's password:
Top-level object must be a mapping
And at this point I have stuck with this error, am I doing something wrong in this steps? also here is the configurations
.env
APP_ID=laraveldock
DEPLOY_SERVER=docker#192.168.99.100
DOCKER_REPOSITORY=192.168.99.100:5000/registry:web
REGISTRY=localhost:5000
REGISTRY_USER=docker
REGISTRY_PASSWORD=tcuser
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:25q1JJ78zFzeGYOBIyIndCmuSJBOCaezyW2utE7hE3Y=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_DATABASE=laraveldock
DB_USERNAME=root
DB_PASSWORD=secret
REDIS_PASSWORD=rediz
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
DB_DATABASE=laraveldock
DB_USERNAME=root
DB_PASSWORD=secret
REDIS_PASSWORD=rediz
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
docker-compose.yml
version: '3.7'
# Volumes
volumes:
mysql:
driver: local
redis:
driver: local
services:
# Apache + PHP
app:
environment:
- CONTAINER_ROLE=app
- DB_HOST=db
- DB_PORT=3306
- REDIS_HOST=redis
- REDIS_PORT=6379
env_file: ../.env
ports:
- "80:80"
# Scheduler
scheduler:
user: webdev
environment:
- CONTAINER_ROLE=scheduler
- DB_HOST=db
- DB_PORT=3306
- REDIS_HOST=redis
- REDIS_PORT=6379
env_file: ../.env
# Queue worker
queue:
user: webdev
environment:
- CONTAINER_ROLE=queue
- DB_HOST=db
- DB_PORT=3306
- REDIS_HOST=redis
- REDIS_PORT=6379
env_file: ../.env
# MySQL
db:
image: mysql:5.7
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
- MYSQL_DATABASE=${DB_DATABASE}
ports:
- "3306:3306"
volumes:
- mysql:/var/lib/mysql/
# Redis
redis:
image: redis:5.0
command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD}"]
I spent an hour on this bug. In my case problem was caused by missing docker-compose on remote server.

Resources