We have just successfully created a new container using image called phpMyAdmin slash phpMyAdmin.
It is not an official Docker hub image.
That's why we needed to use this prefix that is actually name of specific user or organization that
has published specific image at Docker Hub.
But this image indeed is very popular and it is used for management of the MySQL database over graphical
user interface.
And now here on this page we see actually welcome page for phpMyAdmin, but we are not able to set the
connection details for MySQL server.
I'm talking about hostname or IP address, but we are able to set username and password for connection
to MySQL server.
And now in this lecture I'll demonstrate you how we are able to set location of the MySQL server for
phpMyAdmin container.
And first let me go to web page where we have downloaded phpMyAdmin image.
It was Docker hub and here is this page in this history list.
Let's go there and let me scroll a bit down to section that explains how we are able to set custom location
of the MySQL server.
Here it is usage with external server.
Now technically MySQL server MySQL container is external related to phpMyAdmin container because they
are currently running at two different servers, two different containers that have different IP addresses.
And if it is the case you need to use this option environment variable PMA underscore Host Let me make
it a bit larger like so.
And here you will see this environment variable and you are able to set it either to hostname of the
MySQL server or use IP address.
And let's first use IP address and see whether we will be able to connect to MySQL server or not.
All right, let's go back to terminal and let's actually stop container phpMyAdmin container that is
currently running.
Let's use control C shutting down this process accepts sigterm signal and actually seek enter should
be sent, but probably seek INT is converted in this case to sigterm.
All right, let's clear terminal and let's again start phpMyAdmin container but now with additional
environment variable dash E but I have told you that we want to set IP address of the MySQL server in
this environment variable Host And first let's find out which IP address is currently used by MySQL
container.
Let's list containers Docker PS and here is currently only MySQL server running.
Let's use Docker exec command here 49 and here let's open up Shell.
And actually I need to add here, dash it like so and here you are able to type hostname dash I and
you'll find out IP address of this container 172 1702 Let me copy it and actually you are able to find
out the IP address of specific container by entering Docker inspect command and here will be ID of the
container this 149 and you'll see same IP address here.
Again, there are two different ways or even more if you want to find out IP address of the container,
you are able to use any of them.
Great.
Let's now clear terminal and let's use Docker run command and let's use again phpMyAdmin with exposed
port dash P external port 8080 internal port 80 and here will be environment variable dash E.
Let's go back to Chrome and here is name of the variable PMA underscore host.
Let's use it PMA underscore host equal sign.
And here let's paste IP address that we have copied.
Actually, I have copied entire section.
Let me remove this part and leave only IP address in place like so.
Great.
And next, let's specify name of the image.
It will be same as before phpMyAdmin slash phpMyAdmin.
Don't forget to add here slash.
Otherwise you will be able to create container because there is no image called phpMyAdmin.
Great.
Let's press enter.
And meanwhile, let's go back to Google Chrome and to this page where we have started connection to
phpMyAdmin recap that now we have created a brand new container and now it has an environment variable
set.
Let's go to this same address and here let's now try to connect to MySQL server using root username
and password will be my dash password.
Again, this password I take from this line that we have used for start of the MySQL server, it is
MySQL root password that is in my case set to my password.
If you used another password, please use your password on this page.
And now let's click go.
And we have successfully logged into MySQL database.
You are able to browse databases.
You see such databases as information schema, MySQL performance schema, Sis and so on.
You are able to create new databases if you want to, but the main idea is that we have successfully
connected to MySQL server MySQL container from the phpMyAdmin container using IP address of the MySQL
server.
Let's go back to terminal and verify quickly which environment variables were set for phpMyAdmin container.
Let's clear a terminal here and let's list containers Docker and let's use Docker Exec and here will
be the ID of the phpMyAdmin container.
This 18A and here let's type env.
We want to list environment variables for this specific container and here is a long list of variables
that were set for this phpmyadmin container like version url php version because actually this container
is running php.
Also, if I'll scroll up you should see environment variable that was set.
Customly.
Where it is, I cannot find it.
Sorry.
This one underscore host and here in this environment variable we have set IP address of the mysql server,
but could you please point me to drawback of usage of such environment variable where we have used the
IP address?
Yes, you are right.
IP address of the MySQL server may change.
And actually I have told you before that Docker host assigns IP address to containers in random fashion.
Actually starts from the address zero two.
But if I'll start MySQL container once again or if I'll start new container using MySQL, it will get
brand new IP address and in such case, phpMyAdmin will not be able to connect to that container because
it will have another IP address.
That's why.
Preferable way of connection between different servers.
It is actually general recommendation not just related to Docker is to use hostnames.
But how we're able to use host names here.
In this case, basically now every container has specific random name here.
You are able to list those names, Docker, PS, you'll find this random name for this container or
this random name for another container.
Question Do we able to use those random names as host names for communication between different containers?
Let me answer this question in the next lecture.
But for now, let's summarize that we were able to create two different containers and actually link
them together, and we were able to connect from phpMyAdmin container to MySQL container.
And here you'll see actually this management page where you are able to manage MySQL database located
at this IP address.
172 1702.
That's all for this lecture.
And next, let's try to explore how we are able to connect different containers over hostnames instead
of IP addresses.
I'll see you in the next lecture.
Bye bye.