How to integrate docker based project with skywalking agent


Introduction to skywalking

Skywalking is an open source application performance monitoring system, including index monitoring, distributed tracking and distributed system performance diagnosis

Skywalking official Chinese translation document

How to quickly build skywalking

How does the project integrate skywalking

1. Download skywalking agent

The extracted directory is as follows
How to integrate docker based project with skywalking agent

2. Configure skywalking probe for our project

The shape is as follows

java -javaagent:D:apache-skywalking-apm-es7-8.4.0/apache-skywalking-apm-bin-es7/agentskywalking-agent.jar -Dskywalking.agent.service_ Name = display name of current project in skywalking - dskywalking.collector.backend_ service=xxxx:11800 -jar spring-demo-0.0.1-SNAPSHOT.jar

In fact, the official also provides documents to tell us how to configure, as shown in the figure below
How to integrate docker based project with skywalking agent
For more detailed configuration information, you can view the following links

Through the above steps, the project can be integrated with skywalking. However, some small partners report that in the docker environment, they don’t know how to use skywalking agent to bury points. Next, let’s introduce how to integrate docker based deployment projects with skywalking agent

Thinking point: how can skywalking agent be used in projects in docker?

Everyone may understand the truth, that is, put skywalking agent and project into the same docker container. Based on this theory, the following two schemes are derived

Scheme 1: integrate the entire agent folder of skywalking agent into the project to be buried

The shape is shown in the figure below:

How to integrate docker based project with skywalking agent
Then modify the dockerfile file of the project. The modified content is as follows

FROM adoptopenjdk/openjdk8
COPY localtime /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
COPY target/spring-demo-*.jar app.jar
COPY agent /usr/local/agent
ENTRYPOINT [ "sh", "-c", "java  -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=spring-demo -Dskywalking.collector.backend_service= -jar /app.jar" ]

The main of the core is the following two sentences

COPY agent /usr/local/agent
ENTRYPOINT [ "sh", "-c", "java  -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=spring-demo -Dskywalking.collector.backend_service= -jar /app.jar" ]

Copy the agent folder in the project to the / usr / local / agent folder in the container, and then the following operations are the same as using skwalking agent in a normal environment

After integration, see the figure below
How to integrate docker based project with skywalking agent

Scheme 2: when we build the basic image, skywalking agent is also added

For example, when we build the JDK basic image running in Java, we add skywalking agent
How to integrate docker based project with skywalking agent
The dockerfile contents are as follows

FROM adoptopenjdk/openjdk8
COPY localtime /etc/localtime
COPY agent /usr/local/agent
RUN echo "Asia/Shanghai" > /etc/timezone

ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -javaagent:/usr/local/agent/skywalking-agent.jar -Dskywalking.agent.service_name=$SKYWALKING_AGENT_SERVICE_NAME -Dskywalking.collector.backend_service=$SKYWALKING_COLLECTOR_BACKEND_SERVICE -jar /app.jar" ]

Then build the basic image through docker build – t image name or docker compose build

The basic image built in this example is openjdk8 trace agent.

Here are several parameter descriptions: skywalking_ AGENT_ SERVICE_ Name and skywarming_ COLLECTOR_ BACKEND_ Service is an environment variable. You can specify specific environment variable values in docker-compose.yml file or k8s file. Take docker-compose.yml as an example

The configuration is as follows

version: '3.1'
    restart: always
    container_name: spring-demo
    network_mode: bridge
     - "8085:8080"
     - SKYWALKING_AGENT_SERVICE_NAME=spring-demo-test


ONBUILD COPY app.jar app.jar

When Maven is built, we uniformly name the business jars as app.jar, so the first app.jar is the jar of our business project, and the second jar is the jar running in the docker container. In this way, we only need to write this in the dockerfile of the business


The example after integration is shown in the figure below
How to integrate docker based project with skywalking agent


Distributed link tracking is basically a required option in microservices. At present, in addition to skywalking, there are also pinpoint, Jaeger, Zipkin, cat, etc. for open source link tracking on the market. If you are interested, you can learn about it. In addition, this article provides that using skywalking agent in docker container may not be the best solution, so let’s take it as a reference

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]