My scenario is :
application container name: c_sys
application has a database conf file. what command I need to write in conf file so that it connects ci_psql container postgres database. Example that is given in postgres repo info:
docker run --name some-app --link some-postgres:postgres -d application-that-uses-postgres. Both containers are in the same Amazone instance.
I dont know what is “some-app” here!!! I thought of: docker run –name some-app --link ci_psql:postgres -d c_sys. where is password, ip, port option???
please advise.
postgres container name: ci_psql
ci_psql container has database named postgres and user is postgres.
some-app would just be the name that you assign to your application container that you are starting using the c_sys image.
When you use --link, you get a bunch of environment variables that have information about the think you are linking to. If you have username/password information in the environment on the postgres image, that will become visible to the newly launched container. Some goes for the port.
If you run docker run --rm --link ci_psql:postgres busybox env, you’ll see all the environment variables that are available.
thanks Jeff for the reply!!
what this does imply then: application-that-uses-postgres in (docker run --name some-app --link some-postgres:postgres -d application-that-uses-postgres). I am bit confused. Could you please help me how to make database connectivity with application in docker container environment?
I have my postgres container up and running with database and tables set for my app.
I have my playframework app folder which i have to mount while creating container from ingensi/play-framwork image. app folder has a configuration file where DB connection string has to set up. what command should i write in configuration file? or is there a way to connect my postgres container database while creating container from ingensi/play-framwork ?
My redmine application can connect to the postgres database with the information provided in the environment thanks to the --link. It can also connect to the host postgres by name due to /etc/hosts containing an entry for it.
The some-redmine and some-postgres names in this example just refer to the names of the containers involved. I can change those to be pretty much anything I want in a real installation.
Hopefully this gives some perspective on how --link works.
Hi jeff,
I m trying to link two docker images where one is postgresql9.3 official image and other one is my custom image that is my_app.
i wanted to use postgres in my image and tried bellow steps:
step2. docker run --name app --link some-postgres:postgres my_app
getting error in step2
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?
I already had running postgres on host machine and didn’t want to allow connections from network, so I did run temporary postgres instance in container and created database in just two lines:
And if I want to connect to postgres running somewhere-not-dockered do I just proceed as per normal (i.e. supply the connection criteria etc) and get on with life?