Docker – Not able to telnet Linked Container

I have a container A with Dockerfile as follows:

...
FROM ubuntu:latest
MAINTAINER arpitaggarwal "aggarwalarpit.89@gmail.com"
EXPOSE 8080

and another container B with Dockerfile as follows:

  • How to run multiple Docker Containers in different terminals using Docker compose or with Shell?
  • How docker treats fsync on guest filesystem? Is it possible to lost data during host system crash?
  • How to version control Docker containers' data volumes?
  • How to detect if docker run succeeded programmatically?
  • celery won't connect to rabbitmq broker for kubernetes
  • Issue with docker Inter container communication on the isolated bridge
  • ...
    FROM ubuntu:latest
    MAINTAINER arpitaggarwal "aggarwalarpit.89@gmail.com"
    RUN apt-get install -q -y mysql-server
    EXPOSE 3306
    

    Then I started the container B using command:

    docker run -P -it --name db B /bin/bash
    

    And running the command: docker run --rm --name web --link db A env

    gives me below output:

    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    HOSTNAME=a5dd66b72ca8
    DB_PORT=tcp://172.17.0.2:3306
    DB_PORT_3306_TCP=tcp://172.17.0.2:3306
    DB_PORT_3306_TCP_ADDR=172.17.0.2
    DB_PORT_3306_TCP_PORT=3306
    DB_PORT_3306_TCP_PROTO=tcp
    DB_NAME=/web/db
    HOME=/root
    

    Then I logged into container A and run the command: ping db

    which gives me output:

    PING db (172.17.0.2) 56(84) bytes of data.
    64 bytes from db (172.17.0.2): icmp_seq=1 ttl=64 time=0.082 ms
    64 bytes from db (172.17.0.2): icmp_seq=2 ttl=64 time=0.063 ms
    64 bytes from db (172.17.0.2): icmp_seq=3 ttl=64 time=0.065 ms
    64 bytes from db (172.17.0.2): icmp_seq=4 ttl=64 time=0.061 ms
    64 bytes from db (172.17.0.2): icmp_seq=5 ttl=64 time=0.066 ms
    

    And when I tried telnet command with port 3306, as follows:

    telnet 172.17.0.2 3306
    

    gives me output:

    root@9b078c1fed82:/# telnet 172.17.0.2 3306
    Trying 172.17.0.2...
    telnet: Unable to connect to remote host: Connection refused
    

    Any idea, how can I telnet linked container?

    Any help will be appreciated!

  • build Docker images from GitLab
  • unable to import large database to docker mysql container
  • Docker attach delay
  • docker run image causes syntax error /bin/sh
  • How do you use docker-compose from a Gitlab Registry on DigitalOcean?
  • Elasticsearch 2.0.0 cluster zen discovery in docker
  • 2 Solutions collect form web for “Docker – Not able to telnet Linked Container”

    MySQL usually only listens on 127.0.0.1 by default. You need to modify the my.cnf during build and set bind-address to 0.0.0.0. You could accomplish this with something like:

    RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
    

    After receiving the answer by @Andy Shinn, I Updated the container B Dockerfile as below:

    FROM ubuntu:latest
    MAINTAINER arpitaggarwal "aggarwalarpit.89@gmail.com"
    RUN apt-get install -q -y mysql-server
    RUN apt-get install -q -y mysql-client
    RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
    EXPOSE 3306
    

    And when I tried accessing mysql-server from container A as:

    mysql -u root -ppassword -h 172.17.0.2
    

    Gives me error:

    ERROR 1130 (HY000): Host '172.17.0.3' is not allowed to connect to this MySQL server
    

    Which I figured it out is because container A was trying to connect to db container through root user. But In mysql do not allow you to connect though root user remotely. So I work around creating another user in mysql-server with root privileges.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.