# Run oneagent on AWS docker swarm

**URL:** <https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951>\
**Category:** Cloud platforms\
**Tags:** installation, aws, oneagent, docker\
**Created:** [November 8, 2017, 12:02pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951 "2017-11-08T12:02:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard\_wilson](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@richard\_wilson](https://community.dynatrace.com/u/richard_wilson)\
**Post date:** [November 8, 2017, 12:02pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/1 "2017-11-08T12:02:10Z")

</div>

Hi, apologies if this has already been asked, I’ve searched and can’t see anything linked to the issue I’m facing.

I’ve got 2 docker swarms that are linked to an AWS account, I’ve successfully linked the AWS account to our Dynatrace account and getting high level reporting but it says I need to install the OneAgent to get more info about each EC2 instance. The EC2 instances are created as managers and nodes by docker swarm so I don’t have access to the AMI’s that they use. I can modify the cloudformation and include the install commands via the UserData command, but this fails.

Trying to install it manually via SSH I get the following message:

Error: Dynatrace OneAgent cannot be installed inside a docker container, setup won’t continue.

But it isn’t inside a docker container, it’s the host, I’m guessing that because the OS is Alpine, the OneAgent just assumes it’s a container and fails there.

Any suggestions for how I can get OneAgent installed on EC2 instances deployed via docker swarm?

Thanks in advance,

Let me know if you need any more information.

Rich

---

<div class="post-metadata">

**Author:** ![moritz\_becker](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@moritz\_becker](https://community.dynatrace.com/u/moritz_becker)\
**Post date:** [December 10, 2017, 6:13pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/2 "2017-12-10T18:13:50Z")

</div>

When you connect to a Docker Swarm Node/Manager instance created by Docker Swarm for AWS (i.e. via the provided CloudFormation template), then you indeed connect to a container running on this instance, namely the docker4x/shell-aws container. This happens transparently because the host SSH port is forwarded to the docker4x/shell-aws container.

---

<div class="post-metadata">

**Author:** ![moritz\_becker](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@moritz\_becker](https://community.dynatrace.com/u/moritz_becker)\
**Post date:** [December 11, 2017, 3:33pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/3 "2017-12-11T15:33:43Z")

</div>

After hours of trying, here is what I figured out. I have tried to install OneAgent using two approaches.

The following relates to a Docker Swarm on AWS cluster that was created using the CloudFormation template  
[supplied by Docker](https://docs.docker.com/docker-for-aws/). EC2 instances in such a deployment are based on the AMI Moby Linux 17.10.0-ce-aws1 edge (ami-b20bb2dd) for the latest version.

## 1. Install OneAgent on the “real” Docker Host

I first attempted to manage to build a SSH connection to a swarm EC2 instance in order to try the installation. I managed to do that by inserting the following instructions into the User Data section before the rc-service docker restart instruction.

```auto
echo "http://dl-2.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories
apk add --no-cache openssh sudo shadow sed
echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers# start sshd
sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config
mkdir -p ~/.ssh && docker cp shell-aws:/home/docker/.ssh/authorized_keys ~/.ssh/authorized_keys
/etc/init.d/sshd start

```

This allowed me to SSH into the Swarm EC2 instance at docker@{ec2-public-dns}:2222. The next issue was that the provided AMI is based on Alpine Linux but OneAgent requires glibc. I worked around this by installing glibc compatibility using the following commands:

```auto
# install alpine-glibc
wget -q -O /etc/apk/keys/sgerrand.rsa.pub "https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub"
wget "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk"
apk add --force glibc-2.27-r0.apk

```

I then tried to reuse the OneAgent installation instructions provided during the Dynatrace SaaS setup. Before that, I had to install OpenSSL support as well as the trusted root CAs:

```auto
apk update && apk upgrade wget && apk add openssl coreutils && apk --no-cache add ca-certificates

```

The installation commands provided by Dynatrace are as follows:

```auto
wget -O Dynatrace-OneAgent-Linux.sh "https://{ACCOUNT-ID}.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token={API-TOKEN}&arch=x86&flavor=default"
# wget "https://ca.dynatrace.com/dt-root.cert.pem" ; ( echo 'Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha-256"; boundary="--SIGNED-INSTALLER"'; echo ; echo ; echo '----SIGNED-INSTALLER' ; cat Dynatrace-OneAgent-Linux.sh ) | openssl cms -verify -CAfile dt-root.cert.pem > /dev/null
/bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1

```

I needed to deactivate the signature verification because the root ca could not be downloaded:

```auto
Connecting to ca.dynatrace.com (52.85.184.247:443)
wget: error getting response: Connection reset by peer

```

Next, the GLIBC version check carried out by the OneAgent install script fails because it uses ldd --version and ldd in the AMI still targets the musl libc despite the prior installation of glibc compatibility. I manually deactivated the check in the script as a workaround.  
After that, the invocation of base64 failed - it seems that Alpine comes with an uncommon version:

```auto
/bin/base64: unrecognized option: i
BusyBox v1.25.1 (2017-11-23 08:48:46 GMT) multi-call binary.
Usage: base64 [-d] [FILE]
Base64 encode or decode FILE to standard output
        -d Decode data
tar: short read

```

I solved this by simply removing the -i option from the base64 invocation (readonly UNPACK\_BINARY\_ARGS=“-d”).  
The next problem was that the AMI’s root device is not mounted at / and the filesystem mounted as / is a tmpfs with only ~500MB in size. Thus, the installer script terminates because not enough space is available in the default insall path /opt/dynatrace.  
I thought of 2 possible workarounds for this problem:

1. Specify a different install path (e.g. to /var which is mounted on the root device with sufficient memory)
2. Mount the root device in /opt via sudo mount /dev/xvdb1 /opt

I first tried option nr 2 and observed that the agent installation was working, although autostart could not be registered:

```auto
15:11:18 Error: Couldn't add oneagent to autostart. Please adjust and add it manually.
Dynatrace-OneAgent-Linux.sh: line 3305: ex: not found

```

After option nr 2 worked, I did not try option nr 1.

Here are the final instructions - leaving out the ssh stuff - that need to be inserted into the user data section of the Swarm CloudFormation template right before the rc-service docker restart (you may need to adapt the OneAgent download URL):

```auto
"\n",
"# install openssl & ca certs\n",
"apk update && apk upgrade wget && apk add openssl coressl && apk --no-cache add ca-certificates\n",
"# install alpine-glibc\n",
"wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub\n",
"wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk\n",
"apk add --force glibc-2.27-r0.apk\n",
"# install Dynatrace OneAgent\n",
"mkdir -p /opt/dynatrace\n",
"mount /dev/xvdb1 /opt/dynatrace\n",
"if [-d /opt/dynatrace/oneagent]; then\n",
" /opt/dynatrace/oneagent/agent/initscripts/oneagent start\n",
"else\n",
" wget -O Dynatrace-OneAgent-Linux.sh \"https://{ACCOUNT-ID}.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token={API-TOKEN}&arch=x86&flavor=default\"\n",
" sed -i 's/arch_checkGlibc$/: #arch_checkGlibc/;s/readonly UNPACK_BINARY_ARGS=\\\"-di\\\"/readonly UNPACK_BINARY_ARGS=\\\"-d\\\"/' Dynatrace-OneAgent-Linux.sh\n",
" /bin/sh Dynatrace-OneAgent-Linux.sh APP_LOG_CONTENT_ACCESS=1\n",
"fi\n",
"\n",

```

## 2. Use [OneAgent docker image](https://hub.docker.com/r/dynatrace/oneagent/)

I noticed that there is also a docker image for running the OneAgent and tried that as well.

The docker image relies on a volume mount -v /:/mnt/root - this path is hard coded in the entrypoint.sh script. Again, the problem is that / is not mounted in the root device but in a tmpfs device with limited space. Hence, the installation fails due to insufficient space. The only way I was able to get it to work was by removing the volume mount and by adapting the entrypoint.sh script by:

```auto
readonly DOCKER_HOST_ROOT_PREFIX=/

```

## Conclusion

Installing OneAgent on a Swarm EC2 instance works but it would be very nice if Dynatrace could modify their install procedures to make this work out-of-the-box.

---

<div class="post-metadata">

**Author:** ![divya\_sharma](https://avatars.discourse-cdn.com/v4/letter/d/b38774/32.png) [@divya\_sharma](https://community.dynatrace.com/u/divya_sharma)\
**Post date:** [May 7, 2018, 5:19pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/4 "2018-05-07T17:19:41Z")

</div>

I have a Question posted here. Could you please suggest any ideas if you have so?[https://community.dynatrace.com/spaces/482/dynatrace-open-qa/questions/201930/unable-to-get-the-services-running-in-docker-conta.html](https://community.dynatrace.com/spaces/482/dynatrace-open-qa/questions/201930/unable-to-get-the-services-running-in-docker-conta.html)

---

<div class="post-metadata">

**Author:** ![tnoonan](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tnoonan/32/4857_2.png) [@tnoonan](https://community.dynatrace.com/u/tnoonan)\
**Post date:** [October 19, 2018, 1:51pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/5 "2018-10-19T13:51:05Z")

</div>

So, what did your docker run statement look like in its entirety?

---

<div class="post-metadata">

**Author:** ![moritz\_becker](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@moritz\_becker](https://community.dynatrace.com/u/moritz_becker)\
**Post date:** [October 19, 2018, 2:28pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/6 "2018-10-19T14:28:41Z")

</div>

Sorry, but your question does not make sense to me.

---

<div class="post-metadata">

**Author:** ![tnoonan](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/tnoonan/32/4857_2.png) [@tnoonan](https://community.dynatrace.com/u/tnoonan)\
**Post date:** [October 19, 2018, 2:42pm UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/7 "2018-10-19T14:42:49Z")

</div>

Sorry, my bad. Your option #2 of using the OneAgent docker image. I was wondering if you made any changes to the command as it is prescribed in the following link? [Set up Dynatrace OneAgent as a Docker container — Dynatrace Docs](https://www.dynatrace.com/support/help/deploy-dynatrace/oneagent/docker/how-do-i-deploy-dynatrace-oneagent-as-docker-container/) For some odd reason after download and install of the image, in a very similar setup to what you describe, the container fails with the following: First, this is run: The command that we run is:

docker run -d --privileged=true --restart=unless-stopped --pid=host --net=host --ipc=host --name=oneagent -v /:/mnt/root -e ONEAGENT\_INSTALLER\_SCRIPT\_URL=“https://\*\*\*.live.dynatrace.com/api/v1/deployment/installer/agent/unix/def ault/latest?Api-Token=\*\*\*&arch=x86&flavor=default” dynatrace/oneagent APP\_LOG\_CONTENT\_ACCESS=1

Then the output in the docker logs look like this. There’s a check and failure for access rights on an initial mount point but it appears to move along and then fails trying to read the “-e” parameter? Very odd.

20:17:50 Error: Insufficient access rights () on: /var/lib

20:17:50 Error: /var/lib path must be globally readable (r-x permissions for others). 20:17:50 Error: Please adjust the permissions and then retry the installation.

20:17:51 Started agent deployment as a Docker container, PID 30911.

20:17:51 Downloading agent to /tmp/Dynatrace-OneAgent-Linux.sh via https://\*\*\*.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token=\*\*\*&arch=x86&flavor=default

20:17:51 Download was skipped as the agent version did not change

20:17:51 Validating downloaded agent installer 20:17:53 Verification successful 20:17:53 Deploying to: /mnt/host\_root 20:17:53 Starting installer…

readlink: unrecognized option: e

BusyBox v1.25.1 (2016-10-26 16:15:20 GMT) multi-call binary.

Usage: readlink [-fnv] FILE

Display the value of a symlink

-f Canonicalize by following all symlinks …

---

<div class="post-metadata">

**Author:** ![moritz\_becker](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@moritz\_becker](https://community.dynatrace.com/u/moritz_becker)\
**Post date:** [October 20, 2018, 6:50am UTC](https://community.dynatrace.com/t/run-oneagent-on-aws-docker-swarm/8951/8 "2018-10-20T06:50:04Z")

</div>

As far as I can recall I used the prescribed docker run command. Other than that I have no idea what the problem could be in your case. Maybe I will try if the OneAgent docker image still works for me when I have time next week in which case I will update my answer.
