|
| 1 | +# Setup of your environment |
| 2 | + |
| 3 | +Docker Machine provides a unified experience of running containers across multiple cloud platforms. On this page we focus specifically on the [Managed Cloud Platform from Dimension Data](http://cloud.dimensiondata.com/). As a software developer, you may want to handle containers at shared or at on-premises cloud facilities provided by Dimension Data. Follow instructions below and learn how to harness the power of containers, right from your laptop. |
| 4 | + |
| 5 | +As a starting point, the diagram below puts Docker, Docker Machine and Docker Engine in context. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[Docker](https://www.docker.com/) and [Docker Machine](https://docs.docker.com/machine/overview/) are sitting at the development workstation. Docker Machine is a tool that lets you install [Docker Engine](https://www.docker.com/products/docker-engine) on virtual hosts, and manage the hosts with `docker-machine` commands. You can use Machine to create Docker hosts on your local Mac or Windows workstation, on your company network, in your data center, or on cloud providers like AWS or Dimension Data. In other terms, Docker Machine allows software engineers to handle containers almost anywhere on Earth. |
| 10 | + |
| 11 | +Docker Machine interact with any [Managed Cloud Platform](http://cloud.dimensiondata.com/), be it a public, hosted or on-premises cloud facilities delivered by Dimension Data or by one partner of the One Cloud alliance. |
| 12 | + |
| 13 | +## From CloudControl to Docker Machine |
| 14 | + |
| 15 | +The consumption of Docker containers on the Managed Cloud Platform is based on following elements: |
| 16 | +* a working Docker and Docker Machine environment |
| 17 | +* the addition of the Docker Machine driver from Dimension Data |
| 18 | +* MCP credentials |
| 19 | + |
| 20 | +In other terms, if you have already used the CloudControl web interface, then you are fully eligible to consume Docker containers as well, right from your workstation. |
| 21 | + |
| 22 | +## How to install Docker Machine? |
| 23 | + |
| 24 | +The Docker Machine executable can be downloaded and installed directly. For example on Mac and on Linux run following command: |
| 25 | + |
| 26 | +```shell |
| 27 | +$ curl -L https://github.com/docker/machine/releases/download/v0.8.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine |
| 28 | +$ chmod +x /usr/local/bin/docker-machine |
| 29 | +``` |
| 30 | + |
| 31 | +For workstations with Windows or any other operating system, you can download the latest release of Docker Machine from https://github.com/docker/machine/releases |
| 32 | + |
| 33 | + |
| 34 | +As an alternative, on Mac and on Windows, Docker Machine is coming along along with other Docker products when you install the Docker Toolbox. For details, check [the download page for Docker Toolbox](https://www.docker.com/products/docker-toolbox) first, then look either at [Mac installation instructions](https://docs.docker.com/toolbox/toolbox_install_mac/) or [Windows installation instructions](https://docs.docker.com/toolbox/toolbox_install_windows/). |
| 35 | + |
| 36 | +Whatever option you considered, you can quickly check the installation of Docker Machine with following command: |
| 37 | + |
| 38 | +``` |
| 39 | +$ docker-machine –v |
| 40 | +``` |
| 41 | + |
| 42 | +Add [the Docker Machine driver from Dimension Data](https://github.com/DimensionDataResearch/docker-machine-driver-ddcloud/releases) and place the executable in the same directory as `docker-machine` executable (or somewhere on your `PATH`). |
| 43 | + |
| 44 | +Set your MCP credentials in the environment, and the initial password for hosts as well. |
| 45 | + |
| 46 | +On Mac and Linux: |
| 47 | + |
| 48 | +``` |
| 49 | +$ nano ~/.bash_profile |
| 50 | +``` |
| 51 | + |
| 52 | +Insert lines with your secrets: |
| 53 | + |
| 54 | +``` |
| 55 | +# credentials for Docker Machine driver |
| 56 | +export MCP_USER="<your-name>" |
| 57 | +export MCP_PASSWORD='<your-password>' |
| 58 | +export MCP_SSH_BOOTSTRAP_PASSWORD="<root-password>" |
| 59 | +``` |
| 60 | + |
| 61 | +Save the file with `Ctrl-O`, confirm, then exit with `Ctrl-X`. |
| 62 | + |
| 63 | +## Select data centers for your containers |
| 64 | + |
| 65 | +Where do you want to deploy containers? The global network of Managed Cloud Platforms is structured in independent regions. And every region has multiple data centers so that you can architect fault-tolerant systems. In most cases you will consider the data centers that are as close as possible from end-users, and limit network latency. Where data placement is important, select a Managed Cloud Platform in a suitable country, or contract with Dimension Data to add one. |
| 66 | + |
| 67 | +After the selection of a Managed Cloud Platform, you prepare a virtual data centre with the CloudControl web console. A virtual data centre consists at least of: a Network Domain, a VLAN, and appropriate firewall rules. |
| 68 | + |
| 69 | +The below is an example configuration sheet that you can adapt to your own needs. |
| 70 | + |
| 71 | +Managed Cloud Platform: |
| 72 | +* EU6 (in Frankfurt, Germany) |
| 73 | +* in region EU (the nick name for Europe) |
| 74 | + |
| 75 | +Network Domain: |
| 76 | +* name: DockerMachineFox |
| 77 | +* type: Essentials |
| 78 | + |
| 79 | +VLAN: |
| 80 | +* name: DockerMachineNetwork |
| 81 | +* subnet: 10.77.88.0/24 |
| 82 | + |
| 83 | +Firewall rule to accept Docker traffic: |
| 84 | +* name: DockerInbound |
| 85 | +* protocol: TCP over IPv4 |
| 86 | +* from: any host, any port |
| 87 | +* to: any host, port 2376 |
| 88 | + |
| 89 | +Firewall rule to accept SSH traffic: |
| 90 | +* name: SshInbound |
| 91 | +* protocol: TCP over IPv4 |
| 92 | +* from: any host, any port |
| 93 | +* to: any host, port 22 |
| 94 | + |
| 95 | +Firewall rule to accept HTTP traffic: |
| 96 | +* name: HttpInbound |
| 97 | +* protocol: TCP over IPv4 |
| 98 | +* from: any host, any port |
| 99 | +* to: any host, port 80 |
| 100 | + |
| 101 | +Firewall rule to accept HTTPS traffic: |
| 102 | +* name: HttpsInbound |
| 103 | +* protocol: TCP over IPv4 |
| 104 | +* from: any host, any port |
| 105 | +* to: any host, port 443 |
| 106 | + |
| 107 | +Firewall rule to accept HTTP proxy traffic: |
| 108 | +* name: HttpProxyInbound |
| 109 | +* protocol: TCP over IPv4 |
| 110 | +* from: any host, any port |
| 111 | +* to: any host, port 8080 |
| 112 | + |
| 113 | +If your containers accept other protocols over the internet then you will create additional rules accordingly. |
| 114 | + |
| 115 | +## How to create a host with Docker Machine? |
| 116 | + |
| 117 | +Use the command `docker-machine create` with appropriate parameters, and indicate the name of the new host. The sample command below creates the machine `mcp-eu-01` at EU6: |
| 118 | + |
| 119 | +```bash |
| 120 | +$ docker-machine create --driver ddcloud \ |
| 121 | + --ddcloud-region EU \ |
| 122 | + --ddcloud-datacenter EU6 \ |
| 123 | + --ddcloud-networkdomain 'DockerMachineFox' \ |
| 124 | + --ddcloud-vlan 'DockerMachineNetwork' \ |
| 125 | + --ddcloud-ssh-key ~/.ssh/id_rsa \ |
| 126 | + mcp-eu6-01 |
| 127 | +``` |
| 128 | + |
| 129 | +You can check the IP address of the new host, and locate security artifacts, with following command. |
| 130 | + |
| 131 | +```bash |
| 132 | +$ docker-machine config mcp-eu6-01 |
| 133 | +``` |
| 134 | + |
| 135 | +The output should be similar to this: |
| 136 | + |
| 137 | +```bash |
| 138 | +--tlsverify |
| 139 | +--tlscacert="/Users/bernard/.docker/machine/certs/ca.pem" |
| 140 | +--tlscert="/Users/bernard/.docker/machine/certs/cert.pem" |
| 141 | +--tlskey="/Users/bernard/.docker/machine/certs/key.pem" |
| 142 | +-H=tcp://168.128.13.169:2376 |
| 143 | +``` |
| 144 | + |
| 145 | +Now that you have one host up and running you can activate it with following command: |
| 146 | + |
| 147 | +```bash |
| 148 | +$ eval $(docker-machine env mcp-eu6-01) |
| 149 | +``` |
| 150 | + |
| 151 | +As an example, let's try running the official Nginx container: |
| 152 | + |
| 153 | +```bash |
| 154 | +$ docker run -d -p 8080:80 --name httpserver nginx |
| 155 | +``` |
| 156 | + |
| 157 | +In this command, port 80 in the Nginx container is mapped to port 8080 on the host. This is meaning that we can access the default Nginx page from anywhere. Open the link in a web browser, using the IP address given by the `config` command. |
| 158 | + |
| 159 | +``` |
| 160 | +http://168.128.13.169:8080 |
| 161 | +``` |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +Congratulations! At this stage you have created a host and deployed a container, all from your workstation. |
| 166 | + |
| 167 | +## How to stop, start, or restart a host? |
| 168 | + |
| 169 | +At the Managed Cloud Platform a stopped server costs far less than a running server. Therefore, a good practice is to stop unused |
| 170 | +hosts when possible. |
| 171 | + |
| 172 | +```shell |
| 173 | +$ docker-machine stop mcp-eu6-01 |
| 174 | +``` |
| 175 | +You can start a host when you want using the following command. |
| 176 | + |
| 177 | +```shell |
| 178 | +$ docker-machine start mcp-eu6-01 |
| 179 | +``` |
| 180 | + |
| 181 | +If for some reason you have to restart a host, use the following command. |
| 182 | + |
| 183 | +```shell |
| 184 | +$ docker-machine restart mcp-eu6-01 |
| 185 | +``` |
| 186 | + |
| 187 | +## How to handle multiple hosts? |
| 188 | + |
| 189 | +Since it is so easy to create remote hosts with Docker Machine, you can quickly end up with several hosts. |
| 190 | +The list of hosts is shown with following command. |
| 191 | + |
| 192 | +```shell |
| 193 | +$ docker-machine ls |
| 194 | +``` |
| 195 | + |
| 196 | +The output should be similar to this: |
| 197 | + |
| 198 | +``` |
| 199 | +NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS |
| 200 | +mcp-eu6-01 * ddcloud Running tcp://168.128.13.168:2376 v1.12.3 |
| 201 | +mcp-eu6-02 - ddcloud Running tcp://168.128.13.169:2376 v1.12.3 |
| 202 | +``` |
| 203 | + |
| 204 | +In this example, two hosts are available and `mcp-eu6-01` is currently active. This is meaning that all `docker` commands are executed there. |
| 205 | +You can switch to another host with a command like this: |
| 206 | + |
| 207 | +```shell |
| 208 | +$ eval $(docker-machine env mcp-eu6-02) |
| 209 | +``` |
| 210 | + |
| 211 | +## How to execute commands on the host? |
| 212 | + |
| 213 | +Hosts created by Docker Machine are running Linux, so you can login directly: |
| 214 | + |
| 215 | +```shell |
| 216 | +$ docker-machine ssh mcp-eu6-02 |
| 217 | +``` |
| 218 | + |
| 219 | +Command prompt now reflects the fact that you're logged into the host as root: |
| 220 | + |
| 221 | +```shell |
| 222 | +root@mcp-eu6-02:~# |
| 223 | +``` |
| 224 | + |
| 225 | +Type the combination `Ctrl-D` to exit the SSH session. |
| 226 | + |
| 227 | +Note that you can also run a command remotely for example. |
| 228 | + |
| 229 | +```shell |
| 230 | +$ docker-machine ssh mcp-eu6-01 apt-get update |
| 231 | +``` |
| 232 | + |
| 233 | +Not sure what kernel your remote Docker host is using? Type the following: |
| 234 | + |
| 235 | +```shell |
| 236 | +$ docker-machine ssh mcp-eu6-01 uname -r |
| 237 | +``` |
| 238 | + |
| 239 | +## How to remove a host? |
| 240 | + |
| 241 | +After this command all resources attached to the host will be lost, including permanent storage: |
| 242 | + |
| 243 | +```bash |
| 244 | +$ docker-machine rm mcp-eu6-01 |
| 245 | +``` |
0 commit comments