This example illustrates how the SSH plugin can be used to install Docker in a specific version on CentOS 7.5. The example installs Docker and starts the daemon using systemd.
This example modifies the How-to: Install latest Docker version in a Vagrant box with CentOS 7.6 using SSH example.
The model file named linux-vagrant.xml has the content:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <mmd:models xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" > <mmd:variables> <mmd:variable key="tmp-dir" value="/tmp" /> <mmd:variable key="docker-version" value="17.03.1.ce" /> <mmd:variable key="docker-source-config.d" value="docker.conf" /> <mmd:variable key="docker-target-config-dir" value="/etc/systemd/system/docker.service.d" /> <mmd:variable key="docker-target-config.d" value="docker.conf" /> <mmd:variable key="create-user-script" value="create-docker-user.sh" /> </mmd:variables> <mmd:model target-resource="ssh-node1" target-operation="deploy-configuration" description="Create and add Docker user to sudoers" > <mmd:content> <shp:ssh> <shp:copy-to source="modulepath:bin/${create-user-script}" destination="/tmp/${create-user-script}" chmod="775 "/> <shp:execute command="sudo /tmp/${create-user-script}" /> </shp:ssh> </mmd:content> </mmd:model> <mmd:model target-resource="ssh-node1" target-operation="deploy-configuration" description="Update YUM (can take some time)" > <mmd:content> <shp:ssh> <shp:execute command="sudo yum --assumeyes update" /> </shp:ssh> </mmd:content> </mmd:model> <mmd:model target-resource="ssh-node1" target-operation="deploy-configuration" description="Add Docker repository to YUM" > <mmd:content> <shp:ssh> <shp:execute command="sudo yum install -y yum-utils device-mapper-persistent-data lvm2" /> <shp:execute command="sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo" /> <shp:execute command="sudo yum -y update" /> </shp:ssh> </mmd:content> </mmd:model> <mmd:model target-resource="ssh-node1" target-operation="deploy-configuration" description="Install Docker" > <mmd:content> <shp:ssh> <shp:execute command="sudo yum --assumeyes --setopt=obsoletes=0 install docker-ce-${docker-version}-1.el7.centos" /> <shp:execute command="sudo mkdir ${docker-target-config-dir}" /> <shp:copy-to source="modulepath:bin/${docker-source-config.d}" destination="${tmp-dir}/${docker-source-config.d}" chmod="775" /> <shp:execute command="sudo mv ${tmp-dir}/${docker-source-config.d} ${docker-target-config-dir}/${docker-target-config.d}" /> <shp:execute command="sudo systemctl enable docker" /> <shp:execute command="sudo systemctl start docker" /> </shp:ssh> </mmd:content> </mmd:model> <mmd:model target-resource="ssh-node1" target-operation="deploy-configuration" description="Validate Docker installation" > <mmd:content> <shp:ssh> <shp:assert-contains command="sudo systemctl status docker" expected-value="Daemon has completed initialization"/> <shp:assert-contains command="sudo systemctl status docker" expected-value="API listen on /var/run/docker.sock"/> <shp:assert-contains command="sudo systemctl status docker" expected-value="API listen on [::]:8082"/> </shp:ssh> </mmd:content> </mmd:model> <mmd:model target-resource="ssh-node1" target-operation="undeploy-configuration" description="Uninstall Docker" > <mmd:content> <shp:ssh> <shp:execute command="sudo systemctl stop docker.service" /> <shp:execute command="sudo yum -y remove docker-engine.x86_64 " /> <shp:execute command="sudo rm -rf /var/lib/docker" /> </shp:ssh> </mmd:content> </mmd:model> </mmd:models>
Locate the variable:
<mmd:variable key="docker-version" value="17.03.1.ce" />
and replace the value with version of the requested version. Here version 17.03.1.ce will be installed. For a list of the alternate docker versions for CentOS 7, please visit https://download.docker.com/linux/centos/7/x86_64/stable/Packages/