Docker Lab Guide
Lab:01 Installing Docker on ubuntu 12.04 Lab:02 Running a web application in Docker. Lab:03 Building images LAB:04 Networking Container Lab:05 Managing Data Volume Lab:06 Building a java Application using Docker
xcelframeworks Labs 2
Lab:01 Installing Docker on ubuntu 12.04
3
Connect to your ubuntu machine and use following commands to Install Docker on ubuntu.
Try Installing docker using below command.
See the below message it indicates it does not have the dependencies in repository.
4
Install https transport as specified below.
Add the key
Create a file docker.list if does not exists as specified below.
Enter the below repository .
5
Save and exit.Also update the repos.
purge lxc-docker.
6
Install
Select (Y),
7
Use docker ps to see if ny conatiner is running
run a conatiner
Check out the running process and you will find a conatiner with ID and other details.
8
Stop the Conatiner.
Check the log.
Lab:02 Running a web application in Docker. web application we’re going to run a Python Flask application.
9
Use a Command to associate 5000 port with 80.
Go to browser and check
10
Giving a name to the container .We are using –name to get a name of Container to manage it using name.
Now once we have named the container we can use it to refer.
11
Lab:03 Building images
12
13
Create a directory myimage and in that create a file named Dockerfile with below content specifying FROM,MAINTAINER and RUN.
14
Create a image with different tag(test) using IMAGE ID of the image. 15
16
LAB:04 Networking Container
Docker includes support for networking containers through the use of network drivers. By default, Docker provides two network drivers for you, the bridge and the overlay drivers. You can also write a network driver plugin so that you can create your own drivers but that is an advanced task.
Bridge is the default network used by docker.
We can use docker network inspect bridge to get the details of netowrk as show below.
17
Removing Container from network is an easy task we can do that by specifying below command.
18
Creating personal Network is a way of isolating containers .Use below command to create a network.
The -d flag tells Docker to use the bridge driver for the new network.
Inspect the details.
19
Add container to Network. You can add containers to a network when you first run a container.As specified Below.
You will see below given output.
After adding try to inspect again and you will find the network details of conatiner.
20
Launch the web app . Move to db .
Try to ping the IP specified in conatiner.
Docker networking allows you to attach a container to as many networks as you like You can also attach an already running container. Lets attach your running web app to the xcelbridge.
Connect to db again
Now specify web as IP for Ping as specified below.
21
22
Lab:05 Managing Data Volume
23
Adding a Data Volume. Data volumes are designed to persist data, independent of the container’s life cycle. Docker therefore never automatically deletes volumes when you remove a container, nor will it “garbage collect� volumes that are no longer referenced by a container. You can add a data volume to a container using the -v flag with the docker create and docker run command. You can use the -v multiple times to mount multiple data volumes. Now, mount a single volume in your web application container. Before adding stop and remove web container added in previous lab.
Start a Container as specified below.
This creates a new volume. Inspect Volume as specified below.
24
Mounting a read only volume.We can specify a read only volume using following command.
Here you’ve mounted the same /src/webapp directory but you’ve added the ro option to specify that the mount should be read-only.
Note: Docker volume plugins allow you to provision and mount shared storage, such as iSCSI, NFS, or FC.
25
Lab:06 Building a java Application using Docker
26
Create a java program with following code.
Create aDockerfile and enter the following lines in it.
27
Build the following using below program.
28
Run the Container as specified below. You will see the container running. Use curl to run and test the program.
29