SystemTap: Provisioning an AWS EC2-Based Docker Instance

In the first article in our SystemTap series, we learned how to install the powerful diagnostic tool, SystemTap, on an AWS EC2 instance and then wrote our very first “Hello World” script. We now need to explore some of the interesting (and more useful) scripts that come with SystemTap.

Building a SystemTap target environment

To make this article easier to read, we will split it into two parts. In this post, we will provide a Red Hat Enterprise Linux 7 platform container image with Docker on an AWS EC2 instance. After the SystemTap target environment is properly built, the final part will show how to run some serious scripts on a Docker container from its EC2 host to illustrate just how useful SystemTap can be.

Installing Docker on your AWS EC2 instance

To install Docker on an AWS EC2 instance, we’ll enable the “Red Hat Enterprise Linux Server 7 Extra(RPMs)” yum repository that, by default, is disabled.

$ sudo yum repolist disabled
Loaded plugins: amazon-id, rhui-lb
repo id                                                          repo name
rhui-REGION-rhel-server-debug-extras/7Server/x86_64              Red Hat Enterprise Linux Server 7 Extra Debug (Debug RPMs)
rhui-REGION-rhel-server-debug-optional/7Server/x86_64            Red Hat Enterprise Linux Server 7 Optional Debug (Debug RPMs)
rhui-REGION-rhel-server-debug-rh-common/7Server/x86_64           Red Hat Enterprise Linux Server 7 RH Common Debug (Debug RPMs)
rhui-REGION-rhel-server-debug-rhscl/7Server/x86_64               Red Hat Enterprise Linux Server 7 RHSCL Debug (Debug RPMs)
rhui-REGION-rhel-server-debug-supplementary/7Server/x86_64       Red Hat Enterprise Linux Server 7 Supplementary Debug (Debug RPMs)
rhui-REGION-rhel-server-extras/7Server/x86_64                    Red Hat Enterprise Linux Server 7 Extra(RPMs)
rhui-REGION-rhel-server-optional/7Server/x86_64                  Red Hat Enterprise Linux Server 7 Optional (RPMs)
rhui-REGION-rhel-server-releases-source/7Server/x86_64           Red Hat Enterprise Linux Server 7 (SRPMs)
rhui-REGION-rhel-server-rhscl/7Server/x86_64                     Red Hat Enterprise Linux Server 7 RHSCL (RPMs)
rhui-REGION-rhel-server-source-extras/7Server/x86_64             Red Hat Enterprise Linux Server 7 Extra (SRPMs)
rhui-REGION-rhel-server-source-optional/7Server/x86_64           Red Hat Enterprise Linux Server 7 Optional (SRPMs)
rhui-REGION-rhel-server-source-rh-common/7Server/x86_64          Red Hat Enterprise Linux Server 7 RH Common (SRPMs)
rhui-REGION-rhel-server-source-rhscl/7Server/x86_64              Red Hat Enterprise Linux Server 7 RHSCL (SRPMs)
rhui-REGION-rhel-server-source-supplementary/7Server/x86_64      Red Hat Enterprise Linux Server 7 Supplementary (SRPMs)
rhui-REGION-rhel-server-supplementary/7Server/x86_64             Red Hat Enterprise Linux Server 7 Supplementary (RPMs)
repolist: 0

We’ll use the yum-config-manager to enable the repo:

$ sudo yum-config-manager --enable "Red Hat Enterprise Linux Server 7 Extra(RPMs)"

Next, you should search for the Docker package and install it. Yum will take care of its dependencies.

$ sudo yum search docker
Loaded plugins: amazon-id, rhui-lb
rhui-REGION-rhel-server-extras                                                                                    | 2.9 kB  00:00:00
rhui-REGION-rhel-server-releases                                                                                  | 3.7 kB  00:00:00
rhui-REGION-rhel-server-releases-debug                                                                            | 2.9 kB  00:00:00
rhui-REGION-rhel-server-rh-common                                                                                 | 3.8 kB  00:00:00
rhui-REGION-rhel-server-extras/7Server/x86_64/primary_db                                                          |  56 kB  00:00:00
rhui-REGION-rhel-server-extras/7Server/x86_64/updateinfo                                                          |  27 kB  00:00:00
========================================================== N/S matched: docker ==========================================================
docker-logrotate.x86_64 : cron job to run logrotate on docker containers
docker-python.x86_64 : An API client for docker written in Python
docker-registry.noarch : Registry server for Docker
docker-registry.x86_64 : Registry server for Docker
docker-selinux.x86_64 : SELinux policies for Docker
docker.x86_64 : Automates deployment of containerized applications
  Name and summary matches only, use "search all" for everything.
$ sudo yum -y install docker

Once the Docker-related packages are installed, you should enable and start the docker service.

$ sudo systemctl enable docker
ln -s '/usr/lib/systemd/system/docker.service' '/etc/systemd/system/multi-user.target.wants/docker.service'
$ sudo systemctl start docker
$ sudo systemctl status docker
docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled)
   Active: active (running) since Wed 2015-09-16 02:02:26 EDT; 20ms ago
     Docs: http://docs.docker.com
 Main PID: 10738 (docker)
   CGroup: /system.slice/docker.service
           └─10738 /usr/bin/docker -d --selinux-enabled --add-registry registry.access.redhat.com
Sep 16 02:02:00 ip-172-30-0-123.ap-southeast-1.compute.internal systemd[1]: Starting Docker Application Container Engine...
Sep 16 02:02:00 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:00.179717121-04:00" level=inf...k)"
Sep 16 02:02:00 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:00.447391712-04:00" level=err...se"
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.342873074-04:00" level=war....10
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.360314551-04:00" level=inf...se"
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.798683604-04:00" level=inf...t."
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.798853557-04:00" level=inf...e."
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.798869375-04:00" level=inf...on"
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal docker[10738]: time="2015-09-16T02:02:26.798882151-04:00" level=inf...7.1
Sep 16 02:02:26 ip-172-30-0-123.ap-southeast-1.compute.internal systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

In order to use Docker with the ec2-user normal user, we need to create a docker group and add ourselves in it.

$ sudo groupadd docker
$ sudo usermod -aG docker ec2-user
$ grep ^docker /etc/group
dockerroot:x:995:
docker:x:1001:ec2-user

Provisioning Red Hat Enterprise Linux 7 container with Docker

To provision our container with Docker, pull down the Red Hat Enterprise Linux 7 platform container image from Red Hat.

$ docker pull rhel7
Trying to pull repository registry.access.redhat.com/rhel7 ...
82ad5fa11820: Download complete
Status: Downloaded newer image for registry.access.redhat.com/rhel7:latest

Run docker images to list the container we have downloaded.

$ docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.access.redhat.com/rhel7     latest              82ad5fa11820        6 days ago          158.3 MB

Let’s do a quick test to see if everything is working.

$ docker run -ti rhel7 /bin/bash
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
[root@35f99cabc19a /]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.1 (Maipo)
[root@c8a8740808c0 bin]# df -h
Filesystem                                                                                          Size  Used Avail Use% Mounted on
/dev/mapper/docker-202:2-51421425-c8a8740808c0d41b7294f6f2906543740b7a9b54791b6f5bed6a150616b18dd5  9.8G  213M  9.0G   3% /
tmpfs                                                                                               497M     0  497M   0% /dev
shm                                                                                                  64M     0   64M   0% /dev/shm
tmpfs                                                                                               497M   20K  497M   1% /run/secrets
/dev/xvda2                                                                                           10G  3.6G  6.5G  36% /etc/hosts
[root@c8a8740808c0 bin]#

So far so good! We are now ready to run some real troubleshooting scripts against our VMs…which we’ll describe in the final installment of this series.

If you want to learn more on Docker, this is your go-to course Introduction to Docker.

Introduction to Docker

Avatar

Written by

Eugene Teo

Eugene Teo is a director of security at a US-based technology company. He is interested in applying machine learning techniques to solve problems in the security domain.


Related Posts

Valery Calderón Briz
Valery Calderón Briz
— October 22, 2019

How to Go Serverless Like a Pro

So, no servers? Yeah, I checked and there are definitely no servers. Well...the cloud service providers do need servers to host and run the code, but we don’t have to worry about it. Which operating system to use, how and when to run the instances, the scalability, and all the arch...

Read more
  • AWS
  • Lambda
  • Serverless
Avatar
Stuart Scott
— October 16, 2019

AWS Security: Bastion Host, NAT instances and VPC Peering

Effective security requires close control over your data and resources. Bastion hosts, NAT instances, and VPC peering can help you secure your AWS infrastructure. Welcome to part four of my AWS Security overview. In part three, we looked at network security at the subnet level. This ti...

Read more
  • AWS
Avatar
Sudhi Seshachala
— October 9, 2019

Top 13 Amazon Virtual Private Cloud (VPC) Best Practices

Amazon Virtual Private Cloud (VPC) brings a host of advantages to the table, including static private IP addresses, Elastic Network Interfaces, secure bastion host setup, DHCP options, Advanced Network Access Control, predictable internal IP ranges, VPN connectivity, movement of interna...

Read more
  • AWS
  • best practices
  • VPC
Avatar
Stuart Scott
— October 2, 2019

Big Changes to the AWS Certification Exams

With AWS re:Invent 2019 just around the corner, we can expect some early announcements to trickle through with upcoming features and services. However, AWS has just announced some big changes to their certification exams. So what’s changing and what’s new? There is a brand NEW ...

Read more
  • AWS
  • Certifications
Alisha Reyes
Alisha Reyes
— October 1, 2019

New on Cloud Academy: ITIL® 4, Microsoft 365 Tenant, Jenkins, TOGAF® 9.1, and more

At Cloud Academy, we're always striving to make improvements to our training platform. Based on your feedback, we released some new features to help make it easier for you to continue studying. These new features allow you to: Remove content from “Continue Studying” section Disc...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
  • ITIL® 4
  • Jenkins
  • Microsoft 365 Tenant
  • New content
  • Product Feature
  • Python programming
  • TOGAF® 9.1
Avatar
Stuart Scott
— September 27, 2019

AWS Security Groups: Instance Level Security

Instance security requires that you fully understand AWS security groups, along with patching responsibility, key pairs, and various tenancy options. As a precursor to this post, you should have a thorough understanding of the AWS Shared Responsibility Model before moving onto discussi...

Read more
  • AWS
  • instance security
  • Security
  • security groups
Avatar
Jeremy Cook
— September 17, 2019

Cloud Migration Risks & Benefits

If you’re like most businesses, you already have at least one workload running in the cloud. However, that doesn’t mean that cloud migration is right for everyone. While cloud environments are generally scalable, reliable, and highly available, those won’t be the only considerations dri...

Read more
  • AWS
  • Azure
  • Cloud Migration
Joe Nemer
Joe Nemer
— September 12, 2019

Real-Time Application Monitoring with Amazon Kinesis

Amazon Kinesis is a real-time data streaming service that makes it easy to collect, process, and analyze data so you can get quick insights and react as fast as possible to new information.  With Amazon Kinesis you can ingest real-time data such as application logs, website clickstre...

Read more
  • amazon kinesis
  • AWS
  • Stream Analytics
  • Streaming data
Joe Nemer
Joe Nemer
— September 6, 2019

Google Cloud Functions vs. AWS Lambda: The Fight for Serverless Cloud Domination

Serverless computing: What is it and why is it important? A quick background The general concept of serverless computing was introduced to the market by Amazon Web Services (AWS) around 2014 with the release of AWS Lambda. As we know, cloud computing has made it possible for users to ...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
Joe Nemer
Joe Nemer
— September 3, 2019

Google Vision vs. Amazon Rekognition: A Vendor-Neutral Comparison

Google Cloud Vision and Amazon Rekognition offer a broad spectrum of solutions, some of which are comparable in terms of functional details, quality, performance, and costs. This post is a fact-based comparative analysis on Google Vision vs. Amazon Rekognition and will focus on the tech...

Read more
  • Amazon Rekognition
  • AWS
  • Google Cloud Platform
  • Google Vision
Alisha Reyes
Alisha Reyes
— August 30, 2019

New on Cloud Academy: CISSP, AWS, Azure, & DevOps Labs, Python for Beginners, and more…

As Hurricane Dorian intensifies, it looks like Floridians across the entire state might have to hunker down for another big one. If you've gone through a hurricane, you know that preparing for one is no joke. You'll need a survival kit with plenty of water, flashlights, batteries, and n...

Read more
  • AWS
  • Azure
  • Google Cloud Platform
  • New content
  • Product Feature
  • Python programming
Joe Nemer
Joe Nemer
— August 27, 2019

Amazon Route 53: Why You Should Consider DNS Migration

What Amazon Route 53 brings to the DNS table Amazon Route 53 is a highly available and scalable Domain Name System (DNS) service offered by AWS. It is named by the TCP or UDP port 53, which is where DNS server requests are addressed. Like any DNS service, Route 53 handles domain regist...

Read more
  • Amazon
  • AWS
  • Cloud Migration
  • DNS
  • Route 53