docker-machine is a utility that can automate the installation of Docker on a remote host. You can use docker-machine to easily deploy Docker to a virtual machine in the Rapid Access Cloud.
Table of Contents
Setting up Machine on Your Workstation
STEP - I: Setting up Machine environment
...
- Download and Install a compatible version of docker
...
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
- Install the OpenStack command-line tools.
- Download an openrc file.
Create a Security Group
Log in to the RAC Dashboard. Then, either create 4. Create a new security group or add new values in default to the default security group to allow port 80and port 2376 in your RAC’s default security group.:
Info |
---|
Port 80 used by HTTP for our app Port 2376 is used by docker application |
5. Select required flavor, image and other options.
Determine the favor and image you want to use
In a terminal, use the below commands to see the Use below commands will show us available flavors and images on in RAC.
Code Block |
---|
$ source /path/to/your/rc/file $ 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
For the purpose of this tutorial, we will use an m1.small
flavor and the Ubuntu 18.04
image.
Provisioning Docker host
Run the following command:
Code Block |
---|
$ docker-machine create -d openstack |
...
--openstack-flavor-name |
...
Example :
...
m1.small |
...
--openstack-image-name "Ubuntu |
...
18.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.
Code Block |
---|
$ docker-machine ls |
And you should see output similar to the following:
3. After the host is provisioned , check the server environment with the following command.:
Code Block |
---|
$ docker-machine env RAC |
4. Then run:
Code Block |
---|
$ eval $(docker-machine env |
...
(This will override our built-in docker settings to point to our new machine)
...
RAC) |
Configuring and building the application image.
1. Run the below commands to create an application folder:
Code Block |
---|
$ mkdir |
...
myapp
$ cd myapp |
$ cd myapp (go into myapp folder)
2. Create a file named named Dockerfile
.
$ nano Dockerfile (create a file called Dockerfile)
...
:
Code Block |
---|
$ vi Dockerfile
# Alternatively, you can use nano:
$ nano Dockerfile |
Copy below script into your Dockerfile
:
Code Block |
---|
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"] |
...
4. In the same application folder folder, create a file called called index.html
$ nano index.html (create a file called index.html)
Copy the following into the index.html page
:
Code Block |
---|
<!DOCTYPE html> |
...
<html lang="en"> |
...
<head>
...
<head> <meta charset="UTF-8"> |
...
<title>First APP</title> |
...
</head> |
...
<body>
...
<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.
...
Next, run:
Code Block |
---|
$ docker build -t appimage . |
...
Verify the image exists:
Code Block |
---|
$ docker images |
6. Once the image is created run $ docker images to see the list of images.
...
Deploying containers to Docker host remotely
1. After creating To deploy the 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
to your Docker host, run:
Code Block |
---|
$ docker run --name myapp -i -t appimage -p 80:80 |
Verify the container is running with the following command:
Code Block |
---|
$ docker ps |
-a
Type in the IP address of your instance (either a Floating IP address or your IPv6 address) in your web browser to see your container running:4. You can open your browser and type localhost or ip of your instance to see your application running in container.
You can also
...
log in to your docker host directly by running:
Code Block |
---|
$ |
...
$ docker-machine ssh <server_name>
...
docker-machine |
...
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.
...
ssh RAC |