ERROR: for csi_redis Cannot start service redis: Ports are not available: listen tcp 127.0.0.1:6379: bind: address already in use - laravel

I'm trying to install a project that runs:
PHP,
Laravel Framework,
Postgres DB,
NPM/NODE
I've installed postgresql and redis with brew.
When I get to docker-compose up -d I'm getting this error below: (nothing else is running..I'm able to get this to work on another computer but this one doesn't want to play nice, everything similar I've looked up here hasn't worked yet.)
Starting csi_redis ... error
ERROR: for csi_redis Cannot start service redis: Ports are not available: listen tcp 127.0.0.1:6379: bind: address already in use
ERROR: for redis Cannot start service redis: Ports are not available: listen tcp 127.0.0.1:6379: bind: address already in use
ERROR: Encountered errors while bringing up the project.```

When you install Redis with Homebrew, it listens on port 6379 on the host. If your docker-compose.yml file has a section like
version: '3'
services:
redis:
image: redis
ports:
- '127.0.0.1:6379:6379'
that also tries to listen to port 6379 on the host, which produces the error you're seeing.
You probably don't need two Redises for your project, so possibly the simplest answer is to brew uninstall redis, or at least brew services stop redis. You can interact with the containerized Redis the same way as you would have the Brew Redis.
If you need the host Redis for local development but the Docker Redis to run your project, you can pick a different port (or, potentially, delete the ports: entirely)
ports:
- '6380:6379' # keep the second port number the same

Related

Docker compose with Spring Boot Applications

I have two images- caller and callable.
When using docker compose and hitting the url of callable from caller image container, it is not working.
My docker compose file
version: "3.7"
services:
callerc:
image: caller:1.0
ports:
- "8000:8084"
environment:
- URL=callmec/callMe
callmec:
image: callable:1.0
ports:
- "5000:8082"
I get URI not absolute. When i try URL parameter as - http://callmec/callMe" then also it doens't work and says Connection refused.
But when I give the URL as my Machine IPv4 address - http://172.XX.XX.XX:5000/callMe then it works.
While trying "localhost:8000/callOtherService" gave Connection refused error - "callmec:5000/callMe": Connection refused
Kindly guide in case I have missed something.
You don't specify the port when you reference the container : http://callmec/callMe.
It uses the default HTTP port (80) such as http://callmec:80/callMe.
But no socket appears to listen that port on the callmec container.
What you want is : http://callmec:8082/callMe
callmec is not a name entry for 172.XX.XX.XX
If you want to use a local name for the Docker IP 172.XX.XX.XX then you have to add it to your hosts file:
On Linux you have to modify the /etc/hosts file.
Please read this document to see how you must do it on other OS: https://support.rackspace.com/how-to/modify-your-hosts-file/

unable to start kafka and zookeeper using docker; ports 9092 and 2181 are already allocated

I am trying to statrt kafka and zookeeper using this docker file
version: '2'
services:
kafka:
image: landoop/fast-data-dev:cp3.3.0
hostname: kafka-host
ports:
- 29092:29092
- 3030:3030 # Landoop UI
- 8081-8083:8081-8083 # REST Proxy, Schema Registry, Kafka Connect ports
- 9581-9585:9581-9585 # JMX Ports
- 2181:2181 # Zookeeper
- 9092:9092 # Kafka Broker
environment:
ADV_HOST: 127.0.0.1
RUNTESTS: 0
FORWARDLOGS: 0
SAMPLEDATA: 0
but I keep on receiving this error message
Cannot start service kafka: b'driver failed programming external connectivity on endpoint kafka-docker_kafka_1 (a741da2d21a00bb752fc169d579fa39bcdeef0cc88ec560d2e93b8fd287b8b5a): Error starting userland proxy: Bind for 0.0.0.0:9092 failed: port is already allocated'
even after I remove all the images and containers ...
with "sudo lsof -i tcp:9092"
I see some process are going on ... but even after I kill them, using kill -9 PIDsome other appear ...
I solved the problem; kafka and zookeeper were actually already installed locally and brew were running them in the background ... when I uninstalled them, everything was fine!
It seems that one of your containers is still using port 9092 (as sudo lsof -i tcp:9092 shows). Run docker ps to be sure that there is no container running using this port.
Moreover, stopping containers using kill -9 command is not the right way :
if you're using docker-compose (as your example shows), you can run docker-compose down to stop all services (therefore all containers defined in your file). Alternatively, if you want to shutdown a container using only docker command, you have to run docker stop <container_id_or_name>, but I do not recommend that if you're using docker-compose
when you issue a kill -9 command, you're experiencing that containers are restarting over and over because you probably have defined a restart policy on your service (https://docs.docker.com/compose/compose-file/compose-file-v2/#restart). The container started after the other one have exited (caused by kill -9) is using the same ports as the previous, so port 9092 is always used

Setting redis configuration with docker in windows

I want to set up redis configuration in docker.
I have my own redis.conf under D:/redis/redis.conf and have configured it to have bind 127.0.0.1 and have uncommented requirepass foobared
Then used this command to load this configuration in docker:
docker run --volume D:/redis/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf
Next,
I have docker-compose.yml in my application in maven Project under src/resources.
I have the following in my docker-compase.yml
redis:
image: redis
ports:
- "6379:6379"
And i execute the command :
docker-compose up
The Server runs, but when i check with the command:
docker ps -a
it Shows that redis Image runs at 0.0.0.0:6379.
I want it to run at 127.0.0.1.
How do i get that?
isn't my configuration file loading or is it wrong? or my commands are wrong?
Any suggestions are of great help.
PS: I am using Windows.
Thanks
Try to execute:
docker inspect <container_id>
And use "NetworkSettings"->"Gateway" (it must be 172.17.0.1) value instead of 127.0.0.1.
You can't use 127.0.0.1 as your Redis was run in the isolated environment.
Or you can link your containers.
So first of all you should not be worried about redis saying listening on 0.0.0.0:6379. Because redis is running inside the container. And if it doesn't listen on 0.0.0.0 then you won't be able to make any connections.
Next if you want redis to only listen on localhost on localhost then you need to use below
redis:
image: redis
ports:
- "127.0.0.1:6379:6379"
PS: I have not run container or docker for windows with 127.0.0.1 port mapping, so you will have to see if it works. Because host networking in Windows, Mac and Linux are different and may not work this way

Can't access docker container on port 80 on OSX

In my current job we have development environment made with docker-compose.
One container is nginx, which provide routing to other containers.
Everything seems fine and work to my colleague on windows and osx. But on my system (osx El Capitan), there is problem with accessing nginx container on port 80.
There is setup of container from docker-compose.yml
nginx:
build: ./dockerbuild/nginx
ports:
- 80:80
links:
- php
volumes_from:
- app
... and more
In ./dockerbuild/nginx there is nothing special, just nginx config as we know it from everywhere.
When I run everyting with docker-compose create and docker-compose start. Then docker ps give me
3b296c1e4775 docker_nginx "nginx -g 'daemon off" About an hour ago Up 47 minutes 0.0.0.0:80->80/tcp, 443/tcp docker_nginx_1
But when I try to access it for example via curl I get error. curl: (7) Failed to connect to localhost port 80: Connection refused
I try to run container with port 81 and everything works fine.
Port is really binded to docker
22:47 $ sudo lsof -i -n -P | grep TCP
...
com.docke 14718 schovi 38u IPv4 0x6e9c93c51ec4b617 0t0 TCP *:80 (LISTEN)
...
Firewall in osx is turned off and I have no other security.
if you are using docker-for-mac:
Accessing by localhost:80 is correct, though you still have to ensure you do not have a local apache/nginx service running. Often leftovers from boxen/homebrew exist binding that port, because thats what developers did back then :)
if you are using dockertoolbox/virtualbox/whatever hypervisor
You will not be able to access it by localhost, by by the docker-machine ip, so write docker-machine ip default and the use http://$ip:80 in your browser
if that does not help
Ensure your nginx container actually does work, so connect to the container: docker exec -i -t <containerid> bash
and then run ps aux nginx or if telnet is installed try to connect to localhost
Solved!
Problem was, that long long time ago I installed pow (super simple automated rails server which run application on app_name.local domain). And this beast left LaunchAgent script which update pf to forward port 80 to pow port.
In my current job we have development environment made with docker-compose.
A privilege to use.
[W]hen I try to access [nginx on port 80] for example via curl I get error.
Given there's nothing from causing you from accessing docker on your host os you should look at the app running inside the container to ensure it's binding to the correct host, e.g. 0.0.0.0 and not localhost.
For example, if you're running Nuxt inside a container with nuxt-ts observe Nuxt will default to localhost thereby causing the container not to connect to the docker network whereas npx nuxt-ts -H 0.0.0.0 gets things squared away with the container's internal server connecting to the ip of the docker network used (verify ip like docker container inspect d8af01990363).

boot2docker access elasticsearch on localhost

I'm running boot2docker on a Mac for my development. I built a Docker image containing a Jetty server which is connecting to elasticsearch at localhost together with Redis and MySQL.
I'm running docker-compose with a host bridge configuration which looks like the following:
api:
image: api
ports:
- "8080:8080"
environment:
JETTY_ENVIRONMENT: dev
net: "host"
What I want is accessing elasticsearch which I installed on my Mac via localhost:9200.
Try this? I know we're not supposed to answer with links, but I thought it'd be OK since it's a link to a boot2docker file on Github.

Resources