Docker Containers Linking

How to link 2 containers ?

Note:- Before reading this blog, do read my previous blog carefully, otherwise you will not understand how all commands are working in this blog.

To link containers, first you need to install Docker from my previous blog, make sure you installed 1.8.2 version.

Lets start now

First pull the fresh container by typing:-

after pulling it just run the container by typing:-

now it will provide terminal to you,

now you can install apache2 in this container by typing:-

after installation, just commit your container by some name, i would prefer “apache_container” name, lets execute command to commit it:-

now stop all the running container by typing:-

docker stop $(docker ps -aq)

remove all running container by typing:-

now to see your container images, just hit the command:-

you will get two container name:

apache_container
ubuntu:14.04

Now your first container is ready, now lets start with second container & in the second container we will install mysql database & then we will link these two container with each other.

ok lets hit the command and start your default container ubuntu:14.04 by typing:-

now install database in it by typing:-

then restart mysql service once by typing:-

now check your mysql user and password by typing:-

now grant the permission of your database so it would be accessible from remote side too, by typing:-

in the previous command you are granting the complete access of your database to everyone.

First * star stands for all databases and the another one stands for all tables and % stands for everyone…

If you face any problem regarding this, feel free to ask by replying on this post…

now change the bind_address in my.cnf file with your editor (which is located in /etc/mysql/ path) by typing:-

now search the line where bind-address=127.0.0.1 & change it to bind-address=0.0.0.0

now lets commit this container by name, i would prefer “mysql_db” name, ok now lets commit this container by typing:-

now stop all the running container by typing:-

remove all running container by typing:-

now check your container images by typing the command:-

you will get three container name:

apache_container
mysql_db
ubuntu:14.04

now the time is linking these two containers……

Ok now lets run these container to link with each other by typing:-

now you will have to restart mysql service once by typing:-

after previous command you will get terminal of your docker container, now just restart mysql service and exit from that container….

now in daemonize mode your mysql_db container is running, also would like to tell you that we kept “db” name of your mysql_db container because at the time of linking, we will need to hit your container by name.

now lets link your “db” named container with another container by typing:

now in daemonize mode your both container are running and linked as well, now access your web (apache_container) by typing:-

and run the command to access mysql:-

Now you are able to access mysql from another container.

So, Today we learnt how to link two container and share database between them, in my next blog i will tell you about Dockerfile, automatically service restart and installation of Prestashop Framework in container….

FOR ANY TYPE OF QUERY OR HELP, KINDLY CONTACT US

 

 

 

Tag(s) docker
Category(s) Uncategorized
. . .

Comment

Add Your Comment

Be the first to comment.

css.php