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.
Related
Yesterday i created a MariaDB image with this command:
docker run --name test_smdb -e MYSQL_ROOT_PASSWORD=<some_password> -p 3306:3306 -d mariadb:10.4.26
And as here is said:
https://docs.docker.com/config/containers/container-networking/
-p 8080:80 Map TCP port 80 in the container to port 8080 on the Docker host.
So i expected to be able to connect to the database via localhost:3306, from a Python application, running in another container in the same Docker instance (deployed on my machine), but this did not happen. I got:
Can't connect to MariaDB : 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (99)
So after some investigation and following some advices from here:
Docker cannot connect application to MySQL
, executing :
docker network list
docker network inspect <id>
i got the ip of the container and connected to MariaDB, using it.
But i still would like to connect to the MariaDB container, using localhost. How to do that?
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
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 beginner and just started using docker, before posting here I google a lot but a lot of mixed confusing result.
I started docker with this command
docker run -itd --name dockWeb2 -v /var/www/wordpress/ -p 80:80 atozchevara/rpi-apache-php5
hoping I would be able to directly mount wordpress installation onto container , as by default it picks internal path of container /var/www/index.php, to override it I used -v flag. but it doesn't work.
I tried using multiple ports by passing -p arguments again for each port but that too gives error
docker run -itd --name dockWeb3 -v /var/www/wordpress/ -p 80:80 -p 22:22 atozchevara/rpi-apache-php5
66a959e4e99af8122705913005fcae12e2e8a5203da7b77ff1717751314fca28
docker: Error response from daemon: driver failed programming external connectivity on endpoint dockWeb3 (eb42a619a8c79961d35d59e0d8930a92541a20132525055afb3b0d2d87483e7f): Bind for 0.0.0.0:80 failed: port is already allocated.
otherwise Could have uploaded my wordpress using ssh to container's /var/www/ location.
For the first issue if you want to mount a volume from the host you need to use Bind mount a volume
docker run -itd --name dockWeb2 -v your_project_path:/var/www/wordpress/ 0.0.0.0:80 failed: port is already allocated. atozchevara/rpi-apache-php5
For the post using -p 80:80 you are publishing container port 80 to the host port 80, and if the host port is already in use you got an error 0.0.0.0:80 failed: port is already allocated. try to use a different port -p 9090:80.
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.