Running a virtual server

In the repository, you will find two folders containing the necessary Vagrant file to launch either a CentOS 7 or a Ubuntu 14.04 virtual server.

If you would like to use the CentOS 7 vagrant box, change the directory to vagrant-centos:

cd vagrant-centos

Once you are in the vagrant-centos directory, you will see that there is a Vagrant file; this file is all you need to launch a CentOS 7 virtual server. After the virtual server has been booted, the latest version of docker and docker-compose will be installed and the monitoring-docker directory will also be mounted inside the virtual machine using the mount point /monitoring-docker.

To launch the virtual server, simply type the following command:

vagrant up

This will download the latest version of the vagrant box from https://atlas.hashicorp.com/russmckendrick/boxes/centos71 and then boot the virtual server; it's a 450 MB download so it may take several minutes to download; it only has to do this once.

If all goes well, you should see something similar to the following output:

Running a virtual server

Now that you have booted the virtual server, you can connect to it using the following command:

vagrant ssh

Once logged in, you should verify that docker and docker-compose are both available:

Running a virtual server

Finally, you can try running the hello-world container using the following command:

docker run hello-world

If everything goes as expected, you should see the following output:

Running a virtual server

To try something more ambitious, you can run an Ubuntu container with the following command:

docker run -it ubuntu bash

Before we launch and enter the Ubuntu container, lets confirm that we are running the CentOS host machine by checking the release file that can be found in /etc:

Running a virtual server

Now, we can launch the Ubuntu container. Using the same command, we can confirm that we are inside the Ubuntu container by viewing its release file:

Running a virtual server

To exit the container just type in exit. This will stop the container from running, as it has terminated the only running process within the container, which was bash, and returned you to the host CentOS machine.

As you can see here from our CentOS 7 host, we have launched and removed an Ubuntu container.

Both the CentOS 7 and Ubuntu Vagrant files will configure a static IP address on your virtual machine. It is 192.168.33.10; also, there is a DNS record for this IP address available at http://docker.media-glass.es. These will allow you to access any containers that expose themselves to a browser at either http://192.168.33.10/ or http://docker.media-glass.es/.

Tip

The URL http://docker.media-glass.es/ will only work while the vagrant box is up, and you have a container running which serves Web pages.

You can see this in action by running the following command:

docker run -d -p 80:80russmckendrick/nginx-php

Tip

Downloading the example code

The code files for this course are available at https://github.com/EdwinMoses/Docker-Code.

This will download and launch a container running NGINX. You can then go to http://192.168.33.10/ or http://docker.media-glass.es/ in your browser; you should see a forbidden page. This is because we have not yet given NGINX any content to serve (more on this will be covered later in the module):

Running a virtual server

For more examples and ideas, go to the website at http://docs.docker.com/userguide/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset