I'm trying to connect my rails app which is in the docker container and trying to connect that to host machine's Redis server which is running on port 6379.
I'm getting
dockefile
EXPOSE 3000
EXPOSE 6379
sudo docker run -it -e RAILS_ENV=development -p 3000:3000 -p 6379:6380 <containerid>
gives error
Redis::ConnectionError: Connection lost (ECONNRESET)
when redis is running on 6380.
and
when I try to run Redis on 6379 I get the following error
with
sudo docker run -it -e RAILS_ENV=development -p 3000:3000 -p 6379:6379
docker: Error response from daemon: driver failed programming external connectivity on endpoint vigorous_turing (2b5c8e2b4f5df5f1bfcccfdfc87fd5ea78c5c2643de4e00774e7dec67acbd8c4): Error starting userland proxy: listen tcp 0.0.0.0:6379: bind: address already in use.
If Redis is running on the host and you want to communicate outside the container, docker recommends using host.docker.internal.
So instead of specifying localhost as the host in your Redis config, use host.docker.internal. Your Rails app will be able to communicate outside now.
-p 6379:6379 is unnecessary
Related
I'm working on a new scraping project. I already set up redis inside docker by running this
docker run -d --rm --name redis -p 6379:6379 redis:alpine
And then I installed redis client and I've successfully gotten redis to run.
In order to run scrapers locally I need to forward the port for the redis dashboard. I did run this command
redis-cli -h 127.0.0.1 -p 6379
but I'm not sure if that is correct.
Also When I type 127.0.0.1:6379 in browser,The page displaying this
I did search online and didn't get enough helpful resources for windows platform . Does anyone know how to fix this problem? A guidance would be much appreciated !
When you use -p 6379:6379, docker would bind port 6379 of redis container on port 6379 of your host. means that you can connect to this redis via port 6379 even out of localhost, for example in network ...
In this case, command redis-cli -h 127.0.0.1 -p 6379 would be right, and also you can use your network ip instead of localhost ip
If you don't want to connect to this redis over network, it possible not to bind ports, and connect to redis container via its ip, means that use docker run -d --rm --name redis redis:alpine, then try to connect with redis-cli -h CONTAINER_IP -p 6379. you can find container ip with docker inspect redis
Note that browser tries to make connection over http, and won't response any for things like this
I am writing a celery application which needs to connect to redis at the host:
redis://redis:6379 - it has to be this specific has because of the way my other apps are connecting to redis.
I do the following:
# Install redis from docker hub
docker run -name redis -d redis
Then bind to local port:
docker run -d -p 6379:6379 redis
I know how to map it to localhost:6379 but how do i map it to the host redis://redis:6379?
Any ideas?
Add an entry to your /etc/hosts
127.0.0.1 redis
That's it, now hostname redis is resolved to the loopback address. Then you expose the port as usual:
docker run -d -p 6379:6379 redis
I am running Docker container which runs a jar file inside it.
This jar file need an access to Elasticsearch for reading data and this Elasticsearch service is installed on the local machine (Not in Docker Container)
I need to connect to local Elasticsearch service from Docker container to make it work
I wrote EXPOSE 9200 9300 service-port in Dockerfile and my Docker run command is as follows,
"docker run -itd --memory=1g -p 9300:9300 -p 9200:9200 -p service-port:service-port --name service-name service-name -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=2 -XshowSettings:vm"
and when I run this command I get following error,
"docker: Error response from daemon: driver failed programming external connectivity on endpoint service-name (3de884dd9a62a4a989475721cc4cdf9cb6b78f1a8d345e590471d85052d6a4de): Error starting userland proxy: listen tcp 0.0.0.0:9300: bind: address already in use."
P.S = On my Local server I need to keep elasticsearch service ON
Both the EXPOSE line you quote and the docker run -p 9200:9200 -p 9300:9300 options tell Docker that you are running a container that is providing an Elasticsearch server, that you want to have listening for connections on those ports.
If you’re just trying to make an outbound connection to an Elasticsearch service running somewhere else, you don’t need these options and should remove them.
I am on windows 10 ent
Running command: docker container run -d -p 8080:80 --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql
But I am getting this error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint mysql(969f8eac66c92e42a4f19f6f28eec72c6802fea1eabed48dfb382c6a35cbb2ce)Error starting userland proxy: Bind for 0.0.0.0:8080: unexpected error Permission denied.
Need help.
This error is often caused because the port you specified is already in use. Sometimes it is because the current user does not have administrative rights.
If you do not specifically require port 80, try port 8000 or 8080.
docker container run -d -p 8080:8000 --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql
If that doesn't fix it, try executing the command in sudo as some ports are system protected and require a user with admin privileges.
In all such cases where you are not sure which port is free on the host machine, you can try using -P option while running your images and then use docker port to see it's bind with which port.
#>docker container run -d -P --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql
#>docker port mysql
3306/tcp -> 0.0.0.0:32768
docker#default:~$
After this you know which port is free then you can select that one and use your usual command.
#>docker container run -d -p 32768:80 --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql
However I think, instead of 80 - you must expose 3306 port - since the default mysql doesn't provide a web-interface.
Adminer (formerly phpMinAdmin) is a different application that does provide mysql server embedded with it.
I am trying to do this lab and type in the following command:
sudo docker run -it --name bdu_spark2 -P -p 4040:4040 -p 4041:4041 -p 8080:8080 -p 8081:8081 bigdatauniversity/spark2:latest /etc/bootstrap.sh -bash
But I get the following error. Is there a conflict between port 8080 of docker using it and other software trying to use it? I have restarted docker and made sure no other containers are running. Thanks for all the input.
Error response from daemon: Cannot start container 3c62472fe5f8481e5ee957550078f06106b45fc6bffe25669272e2ea924b5f36: failed to create endpoint bdu_spark2 on network bridge: Error starting userland proxy: listen tcp 0.0.0.0:8080: bind: address already in use
This is usually caused because another container is using 8080 port on your docker host.
You can see your running containers by running: $ sudo docker ps
Either stop the other container, or choose a different host port to map your container's 8080 to.
In my case doing this with MySQL, I didn't realize it was because I already had a native MySQL running on that port.
docker run --name db --detach --env="MYSQL_ROOT_PASSWORD=123" --publish=3306:3306 mysql:latest
I did a netstat --all --numeric --program --inet --timers | grep 3306 and noticed it gave me 1418/mysqld. Then I did a ps aux | grep mysql and noticed that was the same process number started by /usr/sbin/mysqld which was my local MySQL instance on my host, nothing to do with containers.
Double check nothing is using those ports, especially 8080, which is very common for stand alone web servers, like those that ship with IDEs.
If you are using that port, you can use the --publish option to specify the host port to be different but still use the same port on the container. i.e. --publish=8081:8080, hostport:containerport.