I have a multiple Laravel local projects and I'm trying to change one projects Redis port, so that it doesn't conflict with another project.
Projects are one the same network so that they can communicate with one another, but they have separate Redis instances.
This is my Redis service inside docker-compose.yml
redis:
image: 'redis:alpine'
ports:
- '6380:6379'
volumes:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
I'm trying to have Redis available on port :6380
.
In Docker Desktop I can see, that port bind seems to work correctly:
My .env
redis section is stock, just changed the port to the new one:
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6380
When I try to run sail artisan cache:clear
I always get RedisException Connection refused
.
I've tried changing the REDIS_HOST
environment variable to be exact as container name. Also tried clearing the config with sail artisan config:clear
. All with no luck.
Note: for some reason the :6379
port is still accessible. I imagine that it shouldn't be as it should be binded to :6380
6380:6379
means port 6379 in the container is going to be available at 6380 on the host however when using sail your app is running in another container and not on the host.
The solution is to just change the port Redis is listening on you can modify your docker-compose file:
redis:
image: 'redis:alpine'
volumes:
- 'sail-redis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
command:
- redis-server
- "--port"
- "6380"
An alternative if you don't want to change the container command would be to configure your app to get to redis via the host:
REDIS_HOST=172.17.0.1
REDIS_PASSWORD=null
REDIS_PORT=6380
Here 172.17.0.1 is what is set up as the host IP of the docker network by default, however your value may vary