Docker : linking and working with multiple containers


Prerequisites

  1. Docker installation from here.
  2. Create an account on Docker Hub

In my previous blog we had a quick overview of Docker technology. I suggest you to have a look at my previous blog for better understanding. Our application can have multiple services running in different containers. So In this blog we will know how to link multiple containers. Here we will take an example of mysql and wordpress. Here wordpress is our front-end and mysql is our back-end.

Please follow these steps carefully-

Steps

1.  Download the images of mysql and wordpress from dockerhub with your account by running these simple commands-

  • $ docker pull mysql
  • $ docker pull wordpress

2. After downloading both images successfully we will run our back-end mysql image by running this command-

  • $ docker run –name demo-mysql -e MYSQL_ROOT_PASSWORD=your-password -d mysql:latest

Here ‘demo-mysql’ is the name of our container and ‘your-password’ is the password of our mysql database. You can change it if you want.

3. Now we are going to run our wordpress image and also we will link our wordpress container to mysql container by running this command-

  • $ docker run –name demo-wordpress –link demo-mysql:mysql -p 8080:80 -d wordpress

Here ‘demo-wordpress’ is the name of our wordpress container. Here we also used –link tag to link wordpress container to mysql container.

4. Now we can check that both the containers are running correctly by running this command-

  • $ docker ps

5. Now just open your browser and go to the address localhost:8080. Here you will find the worpress app runnnig there. Now you can configure your wordpress app.

Thanks.

References


KNOLDUS-advt-sticker

Advertisements
This entry was posted in Devops, Scala and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s