Use docker to deploy tomcat and connect to skywalking

Use docker to deploy tomcat and connect to skywalking

1. Overview

The previous article introduced how to deploy spring boot using docker and connect to skywalking, which described how to build skywalking using docker-compose. This article will not introduce how to build skywalking. Here we will mainly record how to deploy a tomcat using docker and connect to skywalking for service link tracking.

2. Use docker to deploy tomcat and connect to skywalking

The following is a description of how to connect the tomcat application to the skywalking official website:

For more information, please visit the official website: skywalking agent official website

Linux Tomcat 7 / Tomcat 8
Add the following to the first line of tomcat/bin/catalina.sh :

CATALINA_OPTS="$CATALINA_OPTS -javaagent:<skywalking-agent-path>"; export CATALINA_OPTS

Windows Tomcat 7 / Tomcat 8
Add the following to the first line of tomcat/bin/catalina.bat:

set "CATALINA_OPTS=-javaagent:<skywalking-agent-path>"

JAR File or Spring Boot
Add the -javaagent parameter to the application startup command line:

java -javaagent:<skywalking-agent-path> -jar yourApp.jar

Note : The -javaagent parameter must come before the -jar parameter.

Since I am using docker to deploy tomcat, I don't plan to modify the tomcat/bin/catalina.sh file. I check the tomcat/bin/catalina.sh file and see the following description:

image.png

In the figure below, a script that reads setenv.sh is defined:

image.png

This means: do not set variables in the catalina.sh script. In order to separate your custom variables, you should put your custom environment variables in the CATALINA_BASE/bin/setenv.sh file. In addition, after my test, I found that you can directly use the environment variable method to set it. Below I will explain the configuration of both methods.

1. Write custom variables in the setenv.sh file

First, we need to download the skywalking agent. For information about downloading the agent, you can refer to the article at the beginning of this article. Then put the agent in an accessible directory. I am testing here, so I copied the agent directory to the same directory as my Dockerfile. The content of Dockerfile is as follows:

FROM tomcat

LABEL maintaner="xiniao"

COPY agent /usr/skywalking/agent

WORKDIR /usr/local/tomcat/bin

RUN echo 'CATALINA_OPTS="$CATALINA_OPTS -javaagent:/usr/skywalking/agent/skywalking-agent.jar";' > setenv.sh

ENV SW_AGENT_NAME="my-spring-demo" \
    SW_AGENT_COLLECTOR_BACKEND_SERVICES="127.0.0.1:11800"

WORKDIR /usr/local/tomcat/webapps/ROOT

COPY target/my-spring-demo.war my-spring-demo.war

RUN jar -xf my-spring-demo.war

As for other configurations of skywalking agent, they can be defined by environment variables. For example, here we specify the service name displayed in skywalking as ENV SW_AGENT_NAME="my-spring-demo" and the backend service address of skywalking SW_AGENT_COLLECTOR_BACKEND_SERVICES="127.0.0.1:11800" . When we visit the skywalking ui, we can see the following content:

image.png

2. Use environment variables to specify the path of skywalking agent

The detailed Dockerfile content is as follows:

FROM tomcat

LABEL maintaner="xiniao"

COPY agent /usr/skywalking/agent

ENV CATALINA_OPTS="$CATALINA_OPTS -javaagent:/usr/skywalking/agent/skywalking-agent.jar" \
    SW_AGENT_NAME="my-spring-demo-env" \
    SW_AGENT_COLLECTOR_BACKEND_SERVICES="127.0.0.1:11800"

WORKDIR /usr/local/tomcat/webapps/ROOT

COPY target/my-spring-demo.war my-spring-demo.war

RUN jar -xf my-spring-demo.war

Use the following command to build the image:

docker build -t my-spring-demo .

Run the container using the following command:

docker run --rm -p 8080:8080 my-spring-demo

Visit the skywalking ui and you can see the monitoring information as follows:

image.png

Summarize

This article mainly introduces how to use docker to deploy tomact and connect it to skywalking. Since there is not much relevant information on the Internet, I record it here to provide some help to those who need it. There are still some problems here. For example, it is not friendly to directly type the skywalking agent into the image file. I think you can customize a tomcat base image and type the skywalking agent into the base image. In this way, all tomcats can reference this base image to build images and connect to skywalking. If you use k8s for deployment, you can define an initial container in the pod. When the pod starts, copy the skywalking agent in the initial container to our application. I will introduce how to use skywalking in k8s and connect the pod application to skywalking without intrusion in the next article.

This is the end of this article about using docker to deploy tomcat and connect to skywalking. For more relevant content about docker to deploy tomcat and connect to skywalking, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Complete steps for Spring Boot to quickly deploy projects using Docker
  • Springboot integrates docker deployment to implement two ways to build Docker images
  • Example of deploying Spring Boot application using Docker
  • Detailed explanation of the docker deployment practice of the springboot project
  • How to deploy SpringBoot project using Dockerfile
  • How to use docker to deploy spring boot and connect to skywalking

<<:  What is web design

>>:  CSS3 frosted glass effect

Blog    

Recommend

How to create a stylish web page design (graphic tutorial)

"Grand" are probably the two words that ...

The whole process record of Vue export Excel function

Table of contents 1. Front-end leading process: 2...

Negative distance (empathy) - iterative process of mutual influence

Negative distance refers to empathy. Preface (rai...

Summary of constructor and super knowledge points in react components

1. Some tips on classes declared with class in re...

WeChat applet implements a simple dice game

This article shares the specific code of the WeCh...

How to implement Nginx configuration detection service status

1. Check whether the check status module is insta...

Detailed explanation of TypeScript's basic types

Table of contents Boolean Type Number Types Strin...

One minute to experience the smoothness of html+vue+element-ui

Technology Fan html web page, you must know vue f...

Seven ways to implement array deduplication in JS

Table of contents 1. Using Set()+Array.from() 2. ...

Implementation steps of Mysql merge results and horizontal splicing fields

Preface Recently, I was working on a report funct...

How to open ports to the outside world in Alibaba Cloud Centos7.X

In a word: if you buy a cloud server from any maj...

Share the problem of Ubuntu 19 not being able to install docker source

According to major websites and personal habits, ...

XHTML language default CSS style

html,address, blockquote, body,dd,div, dl,dt,fiel...

Summary of several replication methods for MySQL master-slave replication

Asynchronous replication MySQL replication is asy...