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

Recommend

Solve the problem that Docker must use sudo operations

The steps are as follows 1. Create a docker group...

HTML imitates Baidu Encyclopedia navigation drop-down menu function

HTML imitates the Baidu Encyclopedia navigation d...

mysql-8.0.17-winx64 deployment method

1. Download mysql-8.0.17-winx64 from the official...

Solution to mysql server 5.5 connection failure

The solution to the problem that mysql cannot be ...

Learn SQL query execution order from scratch

The SQL query statement execution order is as fol...

How to install Linux online software gcc online

Linux online installation related commands: yum i...

Analysis of the operating principle and implementation process of Docker Hub

Similar to the code hosting service provided by G...

Detailed steps to install Mysql5.7.19 using yum on Centos7

There is no mysql by default in the yum source of...

Self-study of MySql built-in functions knowledge points summary

String functions Check the ascii code value of th...

Vue integrates Tencent TIM instant messaging

This article mainly introduces how to integrate T...

v-html rendering component problem

Since I have parsed HTML before, I want to use Vu...

MySQL 8.0.11 installation summary tutorial diagram

Installation environment: CAT /etc/os-release Vie...

How to hide the border/separation line between cells in a table

Only show the top border <table frame=above>...

WeChat applet realizes horizontal and vertical scrolling

This article example shares the specific code for...