Overview
1 Add desired Docker Send Commands to Gateway Template
2 Enable Docker Permissions for Pulse Agent Account
3 Utilize Docker Send Commands

This guide will show you the steps necessary to utilize Pulse IoT Center ‘Custom Commands’ as remote Send Commands to Run, Start and Stop Docker Containers on Pulse Managed Gateways. The same approach can also be used for non-Docker related Custom Commands.

Pre-Requisites
  • IoT Gateway (Physical or Virtual) Enrolled in Pulse IoT Center
  • Docker installed on Gateway

Note
Screenshots/Steps shown in this guide are for Pulse IoT Center Sprint 11 (Build 14636282). If you are using an earlier version, your Screenshots may vary slightly; however, the basic functionality and approach are the same

Add desired Docker Send Commands to Gateway Template
1A Select Device Templates
1B Edit the Gateway Template that your Enrolled Gateway is utilizing by clicking on the Pencil Icon

2A Click NEXT until you are on the Commands step
2B Click +Add

3A Select Type: Custom Command
3B Name: Docker Run
3C Executable: /bin/sh
3D Click +Add

Note: We are utilizing ‘/bin/sh/ as the Executable in order to create a shell session on the Gateway which we will issue our Docker command within.

4A Name: Docker Run
4B Value : -c, /usr/bin/docker run -td --name ubuntu ubuntu
4C Click DONE
4D Note that we have selected NOT to run this command with root privilege(s). As a result, we will need to grant the user that the Pulse Agent runs via the Gateway (‘iotc’) permission to Docker Management actions on the Gateway via Docker Group Membership (covered later in this guide)

5A Select DONE

6A Select +Add and create Send Commands for the remaining two Docker Commands:

Type : Custom Command
Name: Docker Start
Executable: /bin/sh
Arguments: -c, /usr/bin/docker start ubuntu

Type : Custom Command
Name: Docker Stop
Executable: /bin/sh
Arguments: -c, /usr/bin/docker stop ubuntu

7A Click NEXT until you reach the 8 Review step

8A Click SAVE

Enable Docker Permissions for Pulse Agent Account
Since we are not electing to run these Send Commands with root privileges, we need to grant the account that the Pulse Agent runs via (‘iotc’) rights to issue Docker commands. We can accomplish this by adding the iotc user to the docker group.
1 SSH to your Gateway and issue the following commands
sudo groupadd docker (note: this group may already exist)
sudo usermod -aG docker iotc
cat /etc/group | grep docker

2 Restart the iotc-agent service
sudo service iotc-agent restart

3 Verify that you do not have an Ubuntu Container running on the Gateway
sudo docker ps -a

Utilize Docker Send Commands
1A Return to Pulse UI and select Devices
1B Click your Gateway

2A Select horizontal ellipses
2B Click Commands

3A Select SEND COMMAND
3B Select Command: Docker Run
3C Note that we could modify the Docker command line variables if desired. For now, do not modify.
3D Click SEND COMMAND

4A By default, the Gateway checks in with Pulse every 5 minutes to see if there are any pending Send Commands.
4B We can force the Gateway to check in by issuing the following command
sudo /opt/vmware/iotc-agent/bin/DefaultClient get-commands

(Note: Your command result may display a different return message depending on your Pulse Agent version)
5A Let’s check to see if the Ubuntu Container is now present and running
sudo docker ps -a

6A Return to the Pulse Console and check the status of the Docker Run Send Command

7A Let’s Stop the Container by using our Docker Stop Send Command. Select SEND COMMAND
7B Select Command: Docker Stop
7C Click SEND COMMAND

8A Force the Gateway to check for Send Commands
sudo /opt/vmware/iotc-agent/bin/DefaultClient get-commands

9A Verify that the Ubuntu Container is no longer running
sudo docker ps -a

10A Return to the Pulse Console and check the status of the Docker Stop Send Command


After going through these steps it most likely become apparent that you could have utilized a single Docker Send Command if desired (and simply passed in the docker command variables at Send Command runtime) vs. splitting them up into 3x separate commands. Like many things with Pulse IoT Center, there is no ‘single right way’ to approach IoT Management and instead it becomes a matter of user/admin choice.

Thank You - this concludes our Lesson.