How to setup docker to talk to non-dockerized service on same host

I’m trying to set up a docker container (call it docker-client) that will access a MySQL server on mysql-server:3306. mysql-server is the same host that docker-client is on.

I thought I could do this using links and the ambassador pattern, so I tried this:

  • ActiveAdmin uninitialized constant in Ruby on Rails
  • Concourse CI Pipeline giving error :- Get net/http: request canceled while waiting for connection
  • Arbitrary Code Execution with Docker
  • handle docker container data while developing wep application
  • centos6.6 in Dockerfile gives error
  • How can I speed up Rails Docker deployments on Google Cloud Platform?
  • mysql-server$ docker run -d --name mysql_ambassador -e MYSQL_PORT_3306_TCP=tcp://mysql-server:3306 svendowideit/ambassador

    Then I launched my client like this:

    docker run --link mysql_ambassador:mysql-server -i -t ubuntu /bin/bash

    Unfortunately, trying to run mysql on the client gives an error:

    docker-client# mysql -h mysql-server
    ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

    Is there any way for the client to stay dockerized, the server to stay non-dockerized, and the MySQL server to continue running on the standard port 3306?

  • How to Use Docker (or alternative) as Test Environment
  • docker “Couldn't find an alternative telinit implementation to spawn”
  • Docker container that depends on file in other container
  • Is all WSO2 API Manager's configuration saved in the database?
  • sources: where daemon call libcontainer in createContainer
  • Sending email using smtplib in ubuntu docker throws “421 4.3.2 Connection rate limit exceeded”
  • 2 Solutions collect form web for “How to setup docker to talk to non-dockerized service on same host”

    If you need to use hostname there are several options:

    1) use dns with docker ips. Just run with –dns option.

    2) you can use names and alias:
    first run container with name
    docker run -i -t --name test1 test_docker /bin/bash
    than run next container with –link option
    run -i -t --link=test1:test_hostname test_docker /bin/bash
    after that name will be assosiated with proper ip:

    `root@1b6a491653e2:/# cat /etc/hosts   1b6a491653e2       localhost
    ::1     localhost ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters   test_hostname`

    Try using the IP of the host in the environment variable MYSQL_PORT_3306_TCP when starting the ambassador container, instead of the hostname mysql-server.

    However, if you just want to connect to a service on the same host that the docker container is running on, you can do so by using the IP of the host (no need for ambassador), e g

    docker-client# mysql -h
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.