It doesn’t actually matter where you put the New Relic agent. All that matters is that the agent and its support files (including newrelic.yml) are in the same folder, and that you set the -javaagent property of your JVM to point to the location of the newrelic.jar file.
A very important thing to know: your startup script (the one which contains the command that starts your application server) must include Java’s built-in argument called “-javaagent”, and the value of that argument must be the location of wherever you unzipped the newrelic agent. For example, “-javaagent:/usr/local/tomcat/newrelic/newrelic.jar”.
Let’s say that you were testing out deploying a single Java web application, using Docker and New Relic. These 2 files might be all you need:
$ cat Dockerfile
FROM tomcat
RUN mkdir -p /usr/local/tomcat/newrelic/logs
RUN useradd tomcat
RUN chown -R tomcat /usr/local/tomcat/newrelic/logs
ADD ./newrelic/newrelic.jar /usr/local/tomcat/newrelic/newrelic.jar
ADD ./newrelic/newrelic.yml /usr/local/tomcat/newrelic/newrelic.yml
$ cat docker-compose.yml (you’ll need to correct the indents on this one if you want to try it out yourself…)
version: ‘3’
services:
web:
build: .
ports:
- “8080:8080”
environment:
- TOMCAT_USERNAME=tomcat
- TOMCAT_PASSWORD=tomcat
- JAVA_OPTS=-javaagent:/usr/local/tomcat/newrelic/newrelic.jar
Tomcat with environment and Java system properties
FROM tomcat:9
# Add the newrelic.jar and -javaagent parameters
RUN mkdir -p /usr/local/tomcat/newrelic
ADD ./newrelic/newrelic.jar /usr/local/tomcat/newrelic/
ENV JAVA_OPTS="$JAVA_OPTS -javaagent:/usr/local/tomcat/newrelic/newrelic.jar"
# Add the configuration file
ADD ./newrelic/newrelic.yml /usr/local/tomcat/newrelic/
# An example of setting a system property config
ENV JAVA_OPTS="$JAVA_OPTS -Dnewrelic.config.app_name='My Application'"
# An example of setting an Environment variable config
ENV NEW_RELIC_LICENSE_KEY="license_key"
# Config to include the agent logs in Docker's stdout logging
ENV JAVA_OPTS="$JAVA_OPTS -Dnewrelic.config.log_file_name=STDOUT"
EXPOSE 8080
CMD ["catalina.sh", "run"]
How to start an application with the Java agent
FROM openjdk:8
ADD my-application.jar /app
ADD newrelic.jar /app
ADD newrelic.yml /app
ENV NEW_RELIC_APP_NAME="My Application"
ENV NEW_RELIC_LICENSE_KEY="license_key"
ENV NEW_RELIC_LOG_FILE_NAME="STDOUT"
ENTRYPOINT ["java","-javaagent:/app/newrelic.jar","-jar","/app/my-application.jar"]













I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND