How to Link multiple Docker containers together?

Today we are going to look at an interesting concept of linking containers. In our previous post, we pulled LAMP which is a complete stack of Linux, Apache, MySQL and PHP. What if I have Apache and MySQL as a seperate containers. How can I make it work together? This lead me to study

The official link says “Network port mappings are not the only way Docker containers can connect to one another. Docker also has a linking system that allows you to link multiple containers together and send connection information from one to another. When containers are linked, information about a source container can be sent to a recipient container. This allows the recipient to see selected data describing aspects of the source container.”

Let’s try to implement this scenerio and see how it actually works:

This time I would like to try hands on Oracle Linux 7. Fortunately, there are lots of images in Docker registry and hence pulled one as shown:

[root@localhost ~]# docker pull oraclelinux:7
Pulling repository oraclelinux
919c8b6d612d: Download complete
8c3e49cb06dc: Download complete
2794e7de9041: Download complete
Status: Downloaded newer image for oraclelinux:7
[root@localhost ~]#

Let’s pick up MySQL server image from official Oracle repository:

[root@localhost ~]# docker pull mysql/mysql-server
Pulling repository mysql/mysql-server
296ef3e8959e: Download complete
511136ea3c5a: Download complete
ad98bd7101f2: Download complete
8f0a27825a9a: Download complete
c94023a2b919: Download complete
92af7065aa1f: Download complete
37a5e5ad845c: Download complete
4e1a8f6dcb3c: Download complete
0b5ee168e81e: Download complete
51526e13d844: Download complete
d8aaad0b8379: Download complete
Status: Downloaded newer image for mysql/mysql-server:latest
[root@localhost ~]#

Lets see what images has been pulled onto the Docker Engine:

[root@localhost ~]# docker images | grep oracle
oraclelinux 6 c500c430b7a6 4 weeks ago 161.8 MB
oraclelinux 6.6 c500c430b7a6 4 weeks ago 161.8 MB
oraclelinux 7 919c8b6d612d 4 weeks ago 199 MB
oraclelinux 7.1 919c8b6d612d 4 weeks ago 199 MB
oraclelinux latest 919c8b6d612d 4 weeks ago 199 MB
[root@localhost ~]# docker images | grep sql
mysql/mysql-server latest 296ef3e8959e 5 weeks ago 295.3 MB
[root@localhost ~]#

To build a customized container image, we must first build a guest container named webdeliverer, install the web server, and configure it to deliver web server content.

[root@localhost ~]# docker run -it –name webdeliverer oraclelinux:7 /bin/bash
[root@ff41a6f7922a /]#

Lets install apache and related services:

[root@ff41a6f7922a /]# yum install -y httpd perl && yum clean all
ol7_UEKR3 | 1.2 kB 00:00
ol7_latest | 1.4 kB 00:00
(1/5): ol7_UEKR3/x86_64/updateinfo | 32 kB 00:01
(2/5): ol7_latest/x86_64/group | 652 kB 00:01
(3/5): ol7_latest/x86_64/updateinfo | 375 kB 00:02
(4/5): ol7_UEKR3/x86_64/primary | 7.7 MB 00:05
(5/5): ol7_latest/x86_64/primary | 9.4 MB 00:07
ol7_UEKR3 185/185
ol7_latest 9582/9582
Resolving Dependencies
–> Running transaction check
—> Package httpd.x86_64 0:2.4.6-31.0.1.el7 will be installed
–> Processing Dependency: httpd-tools = 2.4.6-31.0.1.el7 for package: httpd-2.4.6-31.0.1.el7.x86_64
–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-31.0.1.el7.x86_64
–> Processing Dependency: for package: httpd-2.4.6-31.0.1.el7.x86_64
–> Processing Dependency: for package: httpd-2.4.6-31.0.1.el7.x86_64
—> Package perl.x86_64 4:5.16.3-285.el7 will be installed
–> Processing Dependency: perl-libs = 4:5.16.3-285.el7 for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl-libs for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl-macros for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-285.el7.x86_64
–> Processing Dependency: for package: 4:perl-5.16.3-285.el7.x86_64
–> Running transaction check
—> Package apr.x86_64 0:1.4.8-3.el7 will be installed
—> Package apr-util.x86_64 0:1.5.2-6.0.1.el7 will be installed
—> Package httpd-tools.x86_64 0:2.4.6-31.0.1.el7 will be installed
—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
—> Package perl-Carp.noarch 0:1.26-244.el7 will be installed
—> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
—> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
—> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
—> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
—> Package perl-Getopt-Long.noarch 0:2.40-2.el7 will be installed
–> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-2.el7.noarch
–> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-2.el7.noarch
—> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
—> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
–> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
–> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
—> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
—> Package perl-Socket.x86_64 0:2.010-3.el7 will be installed
—> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
—> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
—> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
—> Package perl-constant.noarch 0:1.27-2.el7 will be installed
—> Package perl-libs.x86_64 4:5.16.3-285.el7 will be installed
—> Package perl-macros.x86_64 4:5.16.3-285.el7 will be installed
—> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
—> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
–> Running transaction check
—> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
—> Package perl-Pod-Escapes.noarch 1:1.04-285.el7 will be installed
—> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
–> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
–> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
—> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
–> Running transaction check
—> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
–> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
–> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
–> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
—> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
–> Running transaction check
—> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
—> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
—> Package perl-parent.noarch 1:0.225-244.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
httpd x86_64 2.4.6-31.0.1.el7 ol7_latest 1.2 M
perl x86_64 4:5.16.3-285.el7 ol7_latest 8.0 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 ol7_latest 99 k
apr-util x86_64 1.5.2-6.0.1.el7 ol7_latest 91 k
groff-base x86_64 1.22.2-8.el7 ol7_latest 933 k
httpd-tools x86_64 2.4.6-31.0.1.el7 ol7_latest 78 k
mailcap noarch 2.1.41-2.el7 ol7_latest 30 k
perl-Carp noarch 1.26-244.el7 ol7_latest 19 k
perl-Encode x86_64 2.51-7.el7 ol7_latest 1.5 M
perl-Exporter noarch 5.68-3.el7 ol7_latest 28 k
perl-File-Path noarch 2.09-2.el7 ol7_latest 26 k
perl-File-Temp noarch 0.23.01-3.el7 ol7_latest 56 k
perl-Filter x86_64 1.49-3.el7 ol7_latest 76 k
perl-Getopt-Long noarch 2.40-2.el7 ol7_latest 55 k
perl-HTTP-Tiny noarch 0.033-3.el7 ol7_latest 38 k
perl-PathTools x86_64 3.40-5.el7 ol7_latest 82 k
perl-Pod-Escapes noarch 1:1.04-285.el7 ol7_latest 49 k
perl-Pod-Perldoc noarch 3.20-4.el7 ol7_latest 86 k
perl-Pod-Simple noarch 1:3.28-4.el7 ol7_latest 216 k
perl-Pod-Usage noarch 1.63-3.el7 ol7_latest 26 k
perl-Scalar-List-Utils x86_64 1.27-248.el7 ol7_latest 35 k
perl-Socket x86_64 2.010-3.el7 ol7_latest 48 k
perl-Storable x86_64 2.45-3.el7 ol7_latest 76 k
perl-Text-ParseWords noarch 3.29-4.el7 ol7_latest 13 k
perl-Time-HiRes x86_64 4:1.9725-3.el7 ol7_latest 44 k
perl-Time-Local noarch 1.2300-2.el7 ol7_latest 24 k
perl-constant noarch 1.27-2.el7 ol7_latest 18 k
perl-libs x86_64 4:5.16.3-285.el7 ol7_latest 687 k
perl-macros x86_64 4:5.16.3-285.el7 ol7_latest 42 k
perl-parent noarch 1:0.225-244.el7 ol7_latest 12 k
perl-podlators noarch 2.5.1-3.el7 ol7_latest 111 k
perl-threads x86_64 1.87-4.el7 ol7_latest 48 k
perl-threads-shared x86_64 1.43-6.el7 ol7_latest 38 k

Transaction Summary
Install 2 Packages (+31 Dependent packages)

Total download size: 14 M
Installed size: 44 M
Downloading packages:
(1/33): apr-util-1.5.2-6.0.1.el7.x86_64.rpm | 91 kB 00:01
(2/33): apr-1.4.8-3.el7.x86_64.rpm | 99 kB 00:01
(3/33): groff-base-1.22.2-8.el7.x86_64.rpm | 933 kB 00:01
(4/33): httpd-2.4.6-31.0.1.el7.x86_64.rpm | 1.2 MB 00:01
(5/33): mailcap-2.1.41-2.el7.noarch.rpm | 30 kB 00:01
(6/33): httpd-tools-2.4.6-31.0.1.el7.x86_64.rpm | 78 kB 00:01
(7/33): perl-Carp-1.26-244.el7.noarch.rpm | 19 kB 00:00
(8/33): perl-Encode-2.51-7.el7.x86_64.rpm | 1.5 MB 00:01
(9/33): perl-5.16.3-285.el7.x86_64.rpm | 8.0 MB 00:04
(10/33): perl-Exporter-5.68-3.el7.noarch.rpm | 28 kB 00:01
(11/33): perl-File-Temp-0.23.01-3.el7.noarch.rpm | 56 kB 00:02
(12/33): perl-File-Path-2.09-2.el7.noarch.rpm | 26 kB 00:03
(13/33): perl-Filter-1.49-3.el7.x86_64.rpm | 76 kB 00:02
(14/33): perl-Getopt-Long-2.40-2.el7.noarch.rpm | 55 kB 00:02
(15/33): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm | 38 kB 00:01
(16/33): perl-PathTools-3.40-5.el7.x86_64.rpm | 82 kB 00:01
(17/33): perl-Pod-Escapes-1.04-285.el7.noarch.rpm | 49 kB 00:00
(18/33): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm | 86 kB 00:00
(19/33): perl-Pod-Simple-3.28-4.el7.noarch.rpm | 216 kB 00:00
(20/33): perl-Pod-Usage-1.63-3.el7.noarch.rpm | 26 kB 00:00
(21/33): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm | 35 kB 00:00
(22/33): perl-Socket-2.010-3.el7.x86_64.rpm | 48 kB 00:00
(23/33): perl-Storable-2.45-3.el7.x86_64.rpm | 76 kB 00:00
(24/33): perl-Text-ParseWords-3.29-4.el7.noarch.rpm | 13 kB 00:00
(25/33): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm | 44 kB 00:00
(26/33): perl-Time-Local-1.2300-2.el7.noarch.rpm | 24 kB 00:00
(27/33): perl-constant-1.27-2.el7.noarch.rpm | 18 kB 00:00
(28/33): perl-libs-5.16.3-285.el7.x86_64.rpm | 687 kB 00:00
(29/33): perl-macros-5.16.3-285.el7.x86_64.rpm | 42 kB 00:01
(30/33): perl-parent-0.225-244.el7.noarch.rpm | 12 kB 00:00
(31/33): perl-podlators-2.5.1-3.el7.noarch.rpm | 111 kB 00:00
(32/33): perl-threads-1.87-4.el7.x86_64.rpm | 48 kB 00:00
(33/33): perl-threads-shared-1.43-6.el7.x86_64.rpm | 38 kB 00:01
Total 579 kB/s | 14 MB 00:24
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/33
Installing : apr-util-1.5.2-6.0.1.el7.x86_64 2/33
Installing : httpd-tools-2.4.6-31.0.1.el7.x86_64 3/33
Installing : groff-base-1.22.2-8.el7.x86_64 4/33
Installing : 1:perl-parent-0.225-244.el7.noarch 5/33
Installing : perl-HTTP-Tiny-0.033-3.el7.noarch 6/33
Installing : perl-podlators-2.5.1-3.el7.noarch 7/33
Installing : perl-Pod-Perldoc-3.20-4.el7.noarch 8/33
Installing : 1:perl-Pod-Escapes-1.04-285.el7.noarch 9/33
Installing : perl-Encode-2.51-7.el7.x86_64 10/33
Installing : perl-Text-ParseWords-3.29-4.el7.noarch 11/33
Installing : perl-Pod-Usage-1.63-3.el7.noarch 12/33
Installing : 4:perl-macros-5.16.3-285.el7.x86_64 13/33
Installing : perl-Storable-2.45-3.el7.x86_64 14/33
Installing : perl-Exporter-5.68-3.el7.noarch 15/33
Installing : perl-constant-1.27-2.el7.noarch 16/33
Installing : perl-Time-Local-1.2300-2.el7.noarch 17/33
Installing : perl-Socket-2.010-3.el7.x86_64 18/33
Installing : perl-Carp-1.26-244.el7.noarch 19/33
Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 20/33
Installing : perl-PathTools-3.40-5.el7.x86_64 21/33
Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64 22/33
Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch 23/33
Installing : perl-File-Temp-0.23.01-3.el7.noarch 24/33
Installing : perl-File-Path-2.09-2.el7.noarch 25/33
Installing : perl-threads-shared-1.43-6.el7.x86_64 26/33
Installing : perl-threads-1.87-4.el7.x86_64 27/33
Installing : perl-Filter-1.49-3.el7.x86_64 28/33
Installing : 4:perl-libs-5.16.3-285.el7.x86_64 29/33
Installing : perl-Getopt-Long-2.40-2.el7.noarch 30/33
Installing : 4:perl-5.16.3-285.el7.x86_64 31/33
Installing : mailcap-2.1.41-2.el7.noarch 32/33
Installing : httpd-2.4.6-31.0.1.el7.x86_64 33/33
Verifying : perl-HTTP-Tiny-0.033-3.el7.noarch 1/33
Verifying : 4:perl-macros-5.16.3-285.el7.x86_64 2/33
Verifying : mailcap-2.1.41-2.el7.noarch 3/33
Verifying : perl-threads-shared-1.43-6.el7.x86_64 4/33
Verifying : perl-Storable-2.45-3.el7.x86_64 5/33
Verifying : perl-Exporter-5.68-3.el7.noarch 6/33
Verifying : perl-constant-1.27-2.el7.noarch 7/33
Verifying : perl-PathTools-3.40-5.el7.x86_64 8/33
Verifying : 1:perl-Pod-Escapes-1.04-285.el7.noarch 9/33
Verifying : 1:perl-parent-0.225-244.el7.noarch 10/33
Verifying : apr-1.4.8-3.el7.x86_64 11/33
Verifying : groff-base-1.22.2-8.el7.x86_64 12/33
Verifying : perl-File-Temp-0.23.01-3.el7.noarch 13/33
Verifying : 1:perl-Pod-Simple-3.28-4.el7.noarch 14/33
Verifying : httpd-2.4.6-31.0.1.el7.x86_64 15/33
Verifying : apr-util-1.5.2-6.0.1.el7.x86_64 16/33
Verifying : perl-Time-Local-1.2300-2.el7.noarch 17/33
Verifying : perl-Socket-2.010-3.el7.x86_64 18/33
Verifying : perl-Carp-1.26-244.el7.noarch 19/33
Verifying : perl-podlators-2.5.1-3.el7.noarch 20/33
Verifying : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 21/33
Verifying : perl-Scalar-List-Utils-1.27-248.el7.x86_64 22/33
Verifying : httpd-tools-2.4.6-31.0.1.el7.x86_64 23/33
Verifying : perl-Pod-Usage-1.63-3.el7.noarch 24/33
Verifying : perl-Encode-2.51-7.el7.x86_64 25/33
Verifying : 4:perl-5.16.3-285.el7.x86_64 26/33
Verifying : perl-Getopt-Long-2.40-2.el7.noarch 27/33
Verifying : perl-File-Path-2.09-2.el7.noarch 28/33
Verifying : perl-threads-1.87-4.el7.x86_64 29/33
Verifying : perl-Filter-1.49-3.el7.x86_64 30/33
Verifying : perl-Pod-Perldoc-3.20-4.el7.noarch 31/33
Verifying : perl-Text-ParseWords-3.29-4.el7.noarch 32/33
Verifying : 4:perl-libs-5.16.3-285.el7.x86_64 33/33

httpd.x86_64 0:2.4.6-31.0.1.el7 perl.x86_64 4:5.16.3-285.el7

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.0.1.el7
groff-base.x86_64 0:1.22.2-8.el7
httpd-tools.x86_64 0:2.4.6-31.0.1.el7
mailcap.noarch 0:2.1.41-2.el7
perl-Carp.noarch 0:1.26-244.el7
perl-Encode.x86_64 0:2.51-7.el7
perl-Exporter.noarch 0:5.68-3.el7
perl-File-Path.noarch 0:2.09-2.el7
perl-File-Temp.noarch 0:0.23.01-3.el7
perl-Filter.x86_64 0:1.49-3.el7
perl-Getopt-Long.noarch 0:2.40-2.el7
perl-HTTP-Tiny.noarch 0:0.033-3.el7
perl-PathTools.x86_64 0:3.40-5.el7
perl-Pod-Escapes.noarch 1:1.04-285.el7
perl-Pod-Perldoc.noarch 0:3.20-4.el7
perl-Pod-Simple.noarch 1:3.28-4.el7
perl-Pod-Usage.noarch 0:1.63-3.el7
perl-Scalar-List-Utils.x86_64 0:1.27-248.el7
perl-Socket.x86_64 0:2.010-3.el7
perl-Storable.x86_64 0:2.45-3.el7
perl-Text-ParseWords.noarch 0:3.29-4.el7
perl-Time-HiRes.x86_64 4:1.9725-3.el7
perl-Time-Local.noarch 0:1.2300-2.el7
perl-constant.noarch 0:1.27-2.el7
perl-libs.x86_64 4:5.16.3-285.el7
perl-macros.x86_64 4:5.16.3-285.el7
perl-parent.noarch 1:0.225-244.el7
perl-podlators.noarch 0:2.5.1-3.el7
perl-threads.x86_64 0:1.87-4.el7
perl-threads-shared.x86_64 0:1.43-6.el7

Cleaning repos: ol7_UEKR3 ol7_latest
Cleaning up everything
[root@ff41a6f7922a /]#
Now let’s add content for the web server to display in the deliverer container:

[root@ff41a6f7922a /]# echo “Welcome to Collabnix Web Server Deliverer” > /var/www/html/index.html

Use exit command to stop a running container:

[root@ff41a6f7922a /]# exit
[root@localhost ~]#

Let’s create a new Docker image that reflects the contents of the webdeliverer container that I just configured.
The following docker commit command captures the modified container into a new image named collabnix/ol7-webdeliverer:v1
[root@localhost ~]# docker commit -m “OracleLinux-WebDeliverer” `docker ps -l -q` collabnix/ol7-webdeliverer:v1

Let’s verify it:

[root@localhost ~]# docker images
collabnix/ol7-webdeliverer v1 70deec1a2aac About a minute ago 257.9 MB

We don’t need webdeliverer container anymore now since we have created a image out of it:

[root@localhost ~]# docker rm webdeliverer
[root@localhost ~]#
Deploying the configured Docker Image:

Now we can create multiple web servers using new Docker image as template as shown:
[root@localhost ~]# docker run -d –name web2 -p 8081:80 collabnix/ol7-webdeliverer:v1 /usr/sbin/httpd -D

[root@localhost ~]# docker run -d –name web3 -p 8082:80 collabnix/ol7-webdeliverer:v1 /usr/sbin/httpd -D
[root@localhost ~]#

Let’s verify:

[root@localhost ~]# docker ps
24aff6d521e7 collabnix/ol7-webdeliverer:v1 “/usr/sbin/httpd -D 33 seconds ago Up 31 seconds>80/tcp web3
70dc9263262d collabnix/ol7-webdeliverer:v1 “/usr/sbin/httpd -D 45 seconds ago Up 43 seconds>80/tcp web2
Let’s open up text web browser to see if Web page comes up:

[root@localhost ~]# curl http://localhost:8081
Welcome to Collabnix Web Server Deliverer
[root@localhost ~]# curl http://localhost:8082
Welcome to Collabnix Web Server Deliverer

You can check at the web browser too:


Let’s publish to Docker registry:

[root@localhost ~]# docker push collabnix/ol7-webdeliverer
The push refers to a repository [collabnix/ol7-webdeliverer] (len: 1)
Sending image list
Pushing repository collabnix/ol7-webdeliverer (1 tags)
8c3e49cb06dc: Image already pushed, skipping
2794e7de9041: Image already pushed, skipping
919c8b6d612d: Image already pushed, skipping
70deec1a2aac: Image successfully pushed
Pushing tag for rev [70deec1a2aac] on {
[root@localhost ~]#

How to save the image as tar?

[root@localhost ~]# docker save -o webdeliverer.tar collabnix/ol7-webdeliverer:v1
How to limit CPU and memory on the container?

[root@localhost ~]# docker run -it collabnix/ol7-webdeliverer:v1 /bin/bash
[root@d6091eeb3298 /]#
[root@d6091eeb3298 /]#
[root@d6091eeb3298 /]#
[root@d6091eeb3298 /]# free -m
total used free shared buff/cache available
Mem: 1876 159 330 0 1386 1541
Swap: 4031 0 4031
[root@d6091eeb3298 /]#

Say, I want to limit the memory to 512MB rather than 1876MB. Here is the way to do it:

docker run -d –memory=512m -p 8089:80 collabnix/ol7-webdeliverer:v1

Connecting a Web Server Container to a MySQL Container:

Suppose I want to connect my web server container to a container running an instance of MySQL. Docker makes it
possible to link containers together, creating a secure channel for one container to access certain information
from another.

Previously I pulled the Oracle-verified MySQL image from the Docker Hub using the command docker pull
mysql/mysql-server. To run the MySQL image as a container named db, I enter the following command:

[root@localhost ~]# docker run –name db -d -e MYSQL_ROOT_PASSWORD=mysql123 -v /home/data:/var/lib/mysql

[root@localhost ~]# docker ps
1c35297d6999 mysql/mysql-server:latest “/ mysq 5 seconds ago Up 4 seconds

The Docker Hub mysql/mysql-server image includes an entrypoint script ( that sets up the database
server automatically, initializing mysqld. I can view log messages generated from a container using the docker
logs command:

[root@localhost ~]# docker logs db
Running mysql_install_db
2015-05-21 07:05:40 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use —
explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-21 07:05:40 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24) starting as process 22 …
2015-05-21 07:05:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use —
explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-21 07:05:44 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24) starting as process 44 …
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h 1c35297d6999 password ‘new-password’

Alternatively you can run:


which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at

The latest information about MySQL is available on the web at

Support MySQL by buying support/licenses at

Note: new default config file not created.
Please make sure your config file is current

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
–defaults-file argument to mysqld_safe when starting the server

Finished mysql_install_db
MySQL init process in progress…
2015-05-21 07:05:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use —
explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-21 07:05:46 0 [Note] mysqld (mysqld 5.6.24) starting as process 67 …
MySQL init process in progress…
MySQL init process in progress…
MySQL init process done. Ready for start up.
2015-05-21 07:05:49 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use —
explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-21 07:05:49 0 [Note] mysqld (mysqld 5.6.24) starting as process 1 …
[root@localhost ~]#
[root@localhost ~]# docker run –name db -d -e MYSQL_ROOT_PASSWORD=mysql123 -v /home/data:/var/lib/mysql
[root@localhost ~]# docker exec -it db bash
[root@1c35297d6999 /]# ls /var/lib/mysql
auto.cnf ib_logfile1 mysql performance_schema
ib_logfile0 ibdata1 mysql.sock
[root@1c35297d6999 /]#
Lets try logging in MySQL:

[root@1c35297d6999 /]# mysql -h -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.


By linking containers using the –link flag, other application containers can access the MySQL database running in
the db container. This simplifies the separation of database, application, and web services, making it easier to
isolate services in different containers. I can run my web server image as a container and connect it to the
database container using the following command:

$docker run -d –name web1 -v /home/data -p 80:80 \
–link db:db collabnix/webdeliverer:v1

Assuming /etc/httpd/conf/httpd.conf is configured to allow CGI script execution on the web server and some perl script is configured to perform some kind of SQL query, I can run queries against the database in the db container (note
that I can use the docker inspect command to obtain the web server IP address I need for the query):

[root@ol7-host ~]# curl
| customerName |
| Google Inc |
| JP Morgan |
| Cloudbytes India Pvt Ltd |
| …
12 rows in set (0.00 sec)

Please follow and like us:

12 thoughts on “How to Link multiple Docker containers together?

  1. Online video games, a more sturdy download store,
    social networking, and media center performance are all large options for the Wii U.

    More than ever before, Nintendo hopes to seize two completely different audiences: the avid gamers
    who love large-price range franchises like Zelda and Call
    of Duty, and the Wii fans who had been introduced to gaming through
    Wii Sports and Wii Fit. Iceland is a great choice
    if you are a part of a vulnerable group, as it’s at the moment prioritising
    ship to those who most want it. My So-Called Life’ was an incredible
    show with an amazing ensemble forged, but when lead actress Claire Danes left the show simply couldn’t go on without her.
    Occasionally, an irreplaceable lead actor will need to depart –
    like Claire Danes from “My So-Called Life” – and there isn’t any approach to continue.
    Many firms want to place commercials where adults with expendable income will
    see them. Don’t be concerned. Whether you’re a critical foodie searching for a new dining experience or simply want
    to eat out with out the guesswork, there’s an app for that.
    Actually, many individuals start off selling unwanted stuff around their
    house and progress to really looking for goods, say
    at thrift stores, to resell. Drivers should move a background check, however after that, you’re prepared to
    start hauling passengers day or night time.

  2. It’s also possible to e-mail the photos in your album to anyone with
    a pc and an e-mail account. You’ve gotten at your
    disposal a web based picture album that may hold 1,
    000 pictures, and the body may be set to randomly select
    images from this album. When it’s completed downloading, the body hangs up the phone line and
    begins displaying the brand new photos one after
    another. Urbanspoon also has choices to upload your individual pictures for a restaurant and to attach with associates
    who are also using the app. You can vote whether or not you like a restaurant and
    see if different customers have appreciated it. Not solely do you have to deal with
    the break-in itself, but if sensitive monetary info was left accessible for
    the thief, your misfortune is just beginning. Treat them as if
    they’re extra priceless than money — to the thief, they’re.
    It is also making strides towards becoming a more sustainable race.
    Men 18-40 must submit a time that is underneath 3
    hours, while women 18-49 should prove that they will full
    the race in underneath 3 hours, forty five minutes.

  3. It has the same respin function, plus free video games with wins
    positioned in a bonus pot and returned to the reels on the final spin. Wilds can act as others if they can then complete a win, and with
    enough in view, you might easily acquire multiple prizes on the final spin in a series.
    Beetles have the ability to transform into wild symbols at the tip of every sequence of ten spins, probably for multiple wins without delay.
    These can build up during a collection of ten spins, and on the tenth recreation, all golden frames
    magically remodel into wild symbols. They haven’t moved the graphics alongside
    an excessive amount of on this sport, but it’s still a decent-looking slot machine that you’ll find
    in desktop and mobile variations. You’ll see golden jewels representing the gods Anubis the
    dog, Bastet the lion, and the eye of Ra alongside high card symbols.
    You’ll discover it at our hand-picked IGT casinos.
    A nice midrange card can enormously improve
    performance for a few hundred dollars, but you can too find a lot cheaper ones that aren’t
    bleeding-edge that will fit your needs simply wonderful.

  4. From the news feed to the store, more than one thousand
    elements. This set contains more than 60 prepared-made screens and more than a hundred
    and twenty extra parts. Also, all screens are introduced in a gentle and dark type, which will make your application even more usable.
    Also on this template there are screens for monitoring the trade price
    and the expansion of bitcoin. And likewise this template helps Google
    maps, which makes it extra handy. The app makes use of customized animation to make the interface extra visible.
    Never make purchases or test on-line accounts on a public computer or
    public wireless network. Now you may make purchases from
    home, which is very convenient and saves time.

    Now you possibly can easily see what a hotel room or apartment
    will appear to be, you may read critiques from former visitors and make sure
    that this is strictly what you wanted. Companies normally clear and maintain their cars frequently,
    but in case you make a giant mess, you’d better clear it up.

  5. I am curious to find out what blog platform you happen to be working with?
    I’m experiencing some small security issues with my latest website and I
    would like to find something more secure. Do you have
    any recommendations?

  6. The one actual downside is the excessive value. The real magic
    of the GamePad is in how it interacts with games. It excels in CPU and GPU performance
    and dishes up consistently easy and detailed visuals in AAA games
    on its 4K show. In our Rise of the Tomb Raider benchmark, our Asus ROG Zephyrus S17 with Nvidia
    RTX 3080 GPU set to 140W topped the field, edging out the Asus ROG Zephyrus
    X13 with Ryzen eight 5980HS CPU and RTX 3080 GPU set at 150W.

    It additionally proved superior to the Adata XPG 15KC
    with GeForce RTX 3070 set at 145W – the mixture of the S17’s
    i9-11900H processor and RTX 3080 GPU making gentle work of the
    workload within the RoTTR preset. Cinebench’s single-threaded benchmark scores present solely minimal difference amongst
    laptops (consultant of mainstream applications), however, the S17’s
    multi-threaded rating ranked the S17 the second highest amongst our comparability laptops, proving its suitability for
    prime-end gaming and CPU demanding duties like 3D video enhancing.
    That’s sufficient for practically all Mac laptops to cost at full pace
    or while in use.

  7. I’m exyremely impressed wuth your writing
    skills and also with the layout on your blog. Is this a paid theme or
    did you customize it yourself? Anyway keep up thhe excellent quality
    writing, it’s rare to seee a nice blog like this one today.

    How to traain muscles web page how to swing biceps

  8. Kayaalp,L.2006). Kromozomlar gibi bazı biyolojik özelliklerin temelinde, bireyin sahip olduğu ya da sahip
    olması beklenen gonadlar, cinsiyeti belirleyen unsurdur.
    Biyolojik olarak insan, erkek ve dişi, veya interseks olarak adlandırılır.
    Biyolojik ya da tıbbi olarak tedavi gören pek çok kişi için, cinsiyet değişmez bir özellik.

Leave a Reply to Anonymous Cancel reply