Docker - Linking Containers
--link name:alias
Where name is the name of the container we're linking to and alias is an alias for the link name.
Создаем контейнер с сервером
vi Dockerfile
FROM centos:centos6
RUN yum -y install mysql-server
RUN touch /etc/sysconfig/network
RUN service mysqld start && \
sleep 5s && \
mysql -e "GRANT ALL ON *.* to 'root'@'%'; FLUSH PRIVILEGES"
EXPOSE 3306
CMD ["/usr/bin/mysqld_safe"]
$ docker build -rm -t centos6/mysql_server:v01 .
$ docker run -t -i --name mysql_server 96200d183cc5
============================
Создаем контейнер с клиентом
vi Dockerfile
FROM centos:centos6
RUN yum -y install mysql
CMD ["bash"]
$ docker build -rm -t centos6/mysql_client:v01 .
$ docker run -t -i --link mysql_server:mysql_server 4a173a15faa5
# env
HOSTNAME=71ff5486e03a
TERM=xterm
MYSQL_SERVER_PORT_3306_TCP=tcp://172.17.1.14:3306
MYSQL_SERVER_PORT_3306_TCP_PORT=3306
MYSQL_SERVER_PORT=tcp://172.17.1.14:3306
MYSQL_SERVER_PORT_3306_TCP_ADDR=172.17.1.14
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
SHLVL=1
HOME=/
MYSQL_SERVER_NAME=/clever_bartik/mysql_server
MYSQL_SERVER_PORT_3306_TCP_PROTO=tcp
_=/usr/bin/env
# cat /etc/hosts
172.17.1.15 71ff5486e03a
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.1.14 mysql_server
Взято:
http://alexecollins.com/docker-linking-containers/
https://docs.docker.com/userguide/dockerlinks/#docker-container-linking