I am a newbie to docker. I am running Postgresql running on my local machine (i.e. On Mac OS). My application is running in docker. What I want is my application should be able to access PostgreSQL(has got a lot of production data, which can`t be run on docker) service from docker. How to do it? Could anyone give me an example of doing so?
Many thanks in advance
Connect to other containerized services # Run server $ docker run --name mysql_server -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=password mysql # Run client $ docker run --rm --name my_client -it --link mysql_server:mysql_server alpine ping mysql_server > PING mysql_server (172.17. 0.5): 56 data bytes 64 bytes from 172.17.
Your Docker container can connect to the outside world, but the outside world cannot connect to the container. To make the ports accessible for external use or with other containers not on the same network, you will have to use the -P (publish all available ports) or -p (publish specific ports) flag.
Finally, I found a solution to link external services inside docker. Added below lines in the docker-compose.yaml
:
extra_hosts:
my-local-host: 10.0.0.10 #Local machine IP
environment:
- SERVER=http://my-local-host:3000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With