Because Docker now provides a Community Edition and Enterprise Edition of its engine, I upgraded the script. More info here.
In this post I will explain how to deploy a Docker container host based on CentOS 7 in an automated way. I’m using my default CentOS 7 vRA blueprint and the application deployment component of vRA to achieve this goal.
My CentOS 7 vRA blueprint uses some basic vRO integrations such as: automated DNS registration, setting the portgroup in vSphere and placing the VM in the vSphere folder that’s specified in the self-service request. The CentOS blueprint also has the vRA guest agent (gugent) installed, which is required for automated application installation. More information about how to install this agent is available in the documentation.
To successfully install Docker, you need to add the Docker yum repositories to the vSphere template (that’s the source for you blueprint). You can do this in an automated way, but I choose to just add these repositories to the source template.
sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://docs.docker.com/engine/installation/linux/repo_files/centos/docker.repo sudo yum makecache fast
The next step is to create a software component that installs the Docker engine on the virtual machine. We also want to enable the Docker remote api, so we can connect the Docker host to the container integration of vRA (this will be discussed in a future article). The vRA installation action contains the following steps:
#!/bin/bash /usr/bin/yum -y install docker-engine -y /usr/bin/systemctl enable docker /usr/bin/systemctl start docker mkdir /etc/systemd/system/docker.service.d/ echo "[Service]" >> /etc/systemd/system/docker.service.d/docker.conf echo "ExecStart=" >> /etc/systemd/system/docker.service.d/docker.conf echo "ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock" >> /etc/systemd/system/docker.service.d/docker.conf sudo systemctl daemon-reload sudo systemctl restart docker
Note: Remote management is enabled on port 2375 (without encryption) in this example. This is fine for lab usage, but not suitable for production environments.
In vRA this script will look like:
Now we can create the blueprint containing the CentOS template and the Docker software component:
That’s it, we’re set and ready to deploy a containerhost in a automated way. After the request the Docker host will be available, you can the rest the remote Docker API by accessing http://<<ip address of the host>>:2375.
That’s it for now, in a next article we will user the container option of vRA to connect to the container host and deploy some containers.