Table of Contents
Overview Dockerfile snippet How to use the Dockerfile Special instructions for Alpine users
Overview
AppDynamics .NET Agent for Linux supports monitoring .NET Core 2.x and 3.0 applications, and it is becoming more and more popular with customers who use containers to run their applications.
There are several ways to deploy the agent after you download it from https://download.appdynamics.com/. You can include agent files in the Docker file, load them from a sidecar container or share them on a separate volume.
Even though there’s this flexibility of use, we’ve been looking at options to simplify the agent deployment and configuration!
The idea that drove this effort is simple:
Simplify agent download, installation and configuration altogether using Dockerfile features like multi-state builds (https://docs.docker.com/develop/develop-images/multistage-build/)
Obtain agent from the portal using new download API (https://docs.appdynamics.com/display/LATEST/Download+AppDynamics+Software)
Prepare agent binaries and copy them to target container
Configure all required agent properties based on documentation (https://docs.appdynamics.com/display/LATEST/Install+the+.NET+Agent+for+Linux)
Dockerfile snippet
Here is the snippet of a Dockerfile that does all that!
# Download AppDynamics agent during multi-stage docker build
# Insert this portion at the top of your Dockerfile
FROM mcr.microsoft.com/powershell as APPDTOOL
WORKDIR /agent
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# !!!Important: Replace user name and password with proper identify at accounts.appdynamics.com
RUN $user = "<user name for AppDynamics account>"; \
$pwd = "<password for AppDynamics account>"; \
$request = [string]::Format("{{""username"": ""{0}"",""password"": ""{1}"",""scopes"": [""download""]}}", $user, $pwd); \
$token = Invoke-WebRequest -Method POST -Body $request -Uri https://identity.msrv.saas.appdynamics.com/v2.0/oauth/token | ConvertFrom-Json; \
$agents = Invoke-WebRequest -Uri https://download.appdynamics.com/download/downloadfilelatest/ | ConvertFrom-Json; \
$agent = $agents | where { $_.filetype -eq "dotnet-core" -and $_.os -eq "linux" }; \
Invoke-WebRequest -Authentication Bearer -Token (ConvertTo-SecureString -AsPlainText -Force $token.access_token) -Uri $agent.download_path -OutFile agent.zip; \
Expand-Archive ./agent.zip ./files
# Your existing Dockerfile logic needs to be put in here
# ==== BEGIN ===
# ===== END ====
# Insert this line at the end of your existing Dockerfile to copy agent files to an application container
COPY --from=APPDTOOL /agent/files /opt/appdynamics/dotnet
# Mandatory settings required to enable the agent for .NET Core application
ENV CORECLR_PROFILER={57e1aa68-2229-41aa-9931-a6e93bbc64d8} \
CORECLR_ENABLE_PROFILING=1 \
CORECLR_PROFILER_PATH=/opt/appdynamics/dotnet/libappdprofiler.so
# Configure connection to the AppDynamics controller
ENV APPDYNAMICS_CONTROLLER_HOST_NAME=controller.saas.appdynamics.com
ENV APPDYNAMICS_CONTROLLER_PORT=443
ENV APPDYNAMICS_CONTROLLER_SSL_ENABLED=true
ENV APPDYNAMICS_AGENT_ACCOUNT_NAME=account-name
ENV APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY="access-key"
# Configure application identity in AppDynamics
ENV APPDYNAMICS_AGENT_APPLICATION_NAME="My Application"
ENV APPDYNAMICS_AGENT_TIER_NAME="Sample Tier"
ENV APPDYNAMICS_AGENT_REUSE_NODE_NAME=true
ENV APPDYNAMICS_AGENT_REUSE_NODE_NAME_PREFIX="Instance"
How to use the Dockerfile snippet
Dockerfile contains two parts: check the comments to see how to properly insert those into your existing Docker file.
On top of the Dockerfile: insert correct credentials for the account that will be used to pull down the agent from the download portal (this an account at www.appdynamics.com, not the SaaS controller user name). You can also create a custom user that will be used just for download purposes.
At the bottom of the Dockerfile: make sure to include the SaaS controller details and application and tier names.
Special instructions for Alpine users
To get the correct Agent binaries, you will need to update OS match condition to new value "alpine-linux" In the script to get correct agent binaries.
Specify library path on Alpine containers by adding one more line to the bottom: ENV LD_LIBRARY_PATH=/opt/appdynamics/dotnet
This is the first version of this Dockerfile — I’m looking to mature it over time.
So, please, share your feedback, suggestions, and issues with me!
Regards,
-Alex
... View more