Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect external service from docker service

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

like image 969
Sunder Avatar asked Mar 07 '18 09:03

Sunder


People also ask

How do I connect an external service to a Docker container?

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.

Can Docker container connect to outside world?

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.


Video Answer


1 Answers

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
like image 88
Sunder Avatar answered Nov 15 '22 04:11

Sunder