You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

STEP - I:  Setting up Machine environment


1. Download and Install a compatible version of docker app from  https://www.docker.com/

2. Follow the steps to install Openstack command line tools at https://wiki.cybera.ca/display/RAC/Command+Line+Tools
3. Create a openrc.sh file using below script


#!/bin/bash
export OS_REGION_NAME="Calgary"
export OS_VOLUME_API_VERSION=2
export OS_AUTH_URL=https://keystone-yyc.cloud.cybera.ca:5000/v2.0
export OS_USERNAME="<account_username>"
export OS_TENANT_NAME="<account_username>"
echo "Please enter your OpenStack Password: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
You can modify below values in above file and save it as .sh
REGION_NAME can be Calgary or Edmonton
OS_USERNAME is your openstack username 
OS_TENANT_NAME is also your openstack username 


Once modified, run  $ source openrc.sh filepath

Login with your RAC password


4. Create a new security group or add new values in default  security group allow port 80 and port 2376 in your RAC’s default security group.


Port 80 used by HTTP for our app

Port 2376 is used by docker application

5. Select required flavor, image and other options. 

Use below commands will show us available flavors and images on RAC.   

$ openstack flavor list 

$ openstack image list


STEP - II: Provisioning Docker host


1. Check if Docker Machine responds to commands and can find the required driver. It also shows you the options you can configure. 


2. After you have selected all the options you want to configure.

run

$ docker-machine create -d openstack --openstack-flavor-name “flavorname ”  --openstack-image-name “imagename” --openstack-floatingip-pool “public”  --openstack-sec-groups “securitygroup ”  --openstack-ssh-user  “username<name of instance>

Example :

$ docker-machine create -d openstack --openstack-flavor-name "m1.small" --openstack-image-name "Ubuntu 16.04" --openstack-floatingip-pool "public" --openstack-sec-groups "default" --openstack-ssh-user ubuntu RAC

Once the machine is successfully created run below command to see if Instance is running.

$ docker-machine ls


3. After the host is provisioned , check the server environment with the following command.


$ docker-machine env RAC


4. Then run $ eval $(docker-machine env RAC)

(This will override our built-in docker settings to point to our new machine)


STEP-III: Configuring and building the application image. 


1. Run below commands to create an application folder

$ mkdir myapp (create our app folder)

$ cd myapp (go into myapp folder)


2. Create a  file named Dockerfile.

$ nano Dockerfile (create a file called Dockerfile)


3. Copy below script into your dockerfile.

FROM ubuntu:16.04
MAINTAINER yourname <youremail>
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
ENV APACHE_RUN_USER  www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR   /var/log/apache2
ENV APACHE_PID_FILE  /var/run/apache2/apache2.pid
ENV APACHE_RUN_DIR   /var/run/apache2
ENV APACHE_LOCK_DIR  /var/lock/apache2
ENV APACHE_LOG_DIR   /var/log/apache2
RUN mkdir -p $APACHE_RUN_DIR
RUN mkdir -p $APACHE_LOCK_DIR
RUN mkdir -p $APACHE_LOG_DIR
COPY index.html /var/www/html
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]ROM ubuntu:18.04


4. In the same application folder  create a file called index.html


$ nano index.html (create a file called index.html)

Copy the following into the index.html page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>First APP</title>
</head>
<body>
    <h1>This is a imageapp container</h1>
</body>
</html>


5. After doing all the configuration run  $ docker build -t imagename .   to build an application image.

 

Example : $ docker build -t appimage .  

 

6. Once the image is created run  $ docker images to see the list of  images.

 


STEP - IV : Deploying containers to Docker host remotely


1. After creating application image, we will create a container running apache instance inside. 

docker run --name container_name  -i  -t image_name

Example:  docker run --name my_first_apache_instance -i -t imageapp


2. Now run $ docker ps to see our newly build container.

-a 


3. To run our newly created container on port 80 run   $ docker run -p 80:80 image_name

Example:  $ docker run -p 80:80 appimage


4. You can open your browser and type localhost or ip of your instance to see your application running in container. 


You can also see your container  by logging into your Docker-machine instance.


$ docker-machine ssh <server_name>

Example: $ docker-machine ssh RAC

Once connected to server run $ sudo docker ps -all to see all available containers. 



Then type Exit and hit Enter


NOTE: In these examples we have not configured all the options of docker-image. 

Type $ docker-machine  create --help to see all the options you can configure.



This tutorial assumes that you have the following already in place:

  • A RAC account.

  • A stable internet connection.

***********************
  • No labels