SoFunction
Updated on 2025-04-07

Example of implementation of Docker building Skywalking

Skywalking

  • Virtual Machine IP192.168.0.109
  • Nacos Service Addresshttp://192.168.0.109:8848/nacos
  • MySQL Services
    • IP:192.168.0.109
    • port:3306
    • username:root
    • password:root
  • ElasticSearch Services:
    • IP:192.168.0.109
    • port:9200
    • username:elastic
    • password:123456
    • Docker network used by containers:docker network create elastic-net
    • Container name:elasticsearch
  • Kibana Services:
    • IP:192.168.0.109
    • port:5601
    • username:elastic
    • password:123456
    • Test address: http://192.168.0.109:5601

Preparation

  • First prepare the configuration directory and the persistence directory, and give a chestnut:mkdir -p /opt/module/skywalking/{config,data,logs}
  • Solve SkyWalking containersPermission denied(Permission denied) error,chmod -R 777 /opt/module/skywalking

Pull the official Skywalking image

# Pull OAP service imagedocker pull apache/skywalking-oap-server:8.9.0

# Pull UI service imagedocker pull apache/skywalking-ui:8.9.0
  • Note: OAP version and agent version need to be adapted. If the version does not adapt, the page may not be accessible and the agent cannot be reported on the page.

Deploy SkyWalking OAP Server

0. Start the temporary container [Create a temporary test container to copy the configuration file and push the configuration backward]

docker run \
  -d -p 11800:11800 -p 12800:12800  \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

illustrate

  • 11800:OAP service port.
  • 12800: SkyWalking UI service port.
  • --restart always: Container automatic restart policy.

Directory structure description

path illustrate
/skywalking/config Configuration file directory
/skywalking/logs Log file directory
/skywalking/data Data storage directory

Copy SkyWalking configuration file to the host

docker cp skywalking-oap:/skywalking/config     /opt/module/skywalking
docker cp skywalking-oap:/skywalking/logs       /opt/module/skywalking
docker cp skywalking-oap:/skywalking/data       /opt/module/skywalking

# If you need to export all filesdocker cp skywalking-oap:/skywalking     /opt/module

Remove temporary containers

docker stop skywalking-oap
docker rm skywalking-oap

1. Use default storage (H2 database)

Start the SkyWalking OAP container and use the H2 database as storage:

docker run \
  -d -p 11800:11800 -p 12800:12800  \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

illustrate: If the storage type is not specified, the H2 database is used by default.

Description of main directories and files in containers

Directory/File Name illustrate
bin Start scripts and other executable tools such as and.
config Configuration file directory, containing key configuration files, such as (OAP core configuration).
config-examples Configuration example directory, including template configuration for user reference.
Container startup scripts for initializing and starting SkyWalking OAP services.
ext-config Extended configuration file directory for custom extension configuration.
ext-libs Extended library directory for adding plug-ins or dependency libraries.
LICENSE Open source license file for the SkyWalking project.
licenses A collection of licenses for all dependency libraries used in the project.
oap-libs The dependency library folder required by the OAP component.
Project introduction file, including operating guide.
tools Tools directory containing practical tools related to SkyWalking.
zipkin-LICENSE Zipkin integration-related license information.

Core directory description

  • config
    • Contains  , used to configure storage backends, services, etc.
  • oap-libs
    • SkyWalking OAP's runtime dependency library generally does not require manual modification.
  • logs
    • Log directory, store operation logs, and facilitates troubleshooting.
  • ext-libs and ext-config
    • You can add plug-ins or custom extension configurations, with high flexibility.

2. Use ElasticSearch storage

Method 1: Start the SkyWalking OAP service through Docker and use ElasticSearch storage

docker run -d \
  -p 11800:11800 \
  -p 12800:12800 \
  -e SW_STORAGE=elasticsearch \
  -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 \
  -e SW_ES_USER=elastic \
  -e SW_ES_PASSWORD="\"123456\"" \
  --link elasticsearch:elasticsearch \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

Method 2: Start the SkyWalking OAP service through Docker and use ElasticSearch to store [here we use the network of the previous ES container directlyes-net

docker run -d \
  -p 11800:11800 \
  -p 12800:12800 \
  -e SW_STORAGE=elasticsearch \
  -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 \
  -e SW_ES_USER=elastic \
  -e SW_ES_PASSWORD="\"123456\"" \
  --net es-net \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

Notice:

  • -e SW_ES_PASSWORD The password value here is "\"123456\"", and the additional quotes ensure that it is correctly parsed into a string.

Method 3: Directly specify the IP address of the ElasticSearch service

docker run \
  -d -p 11800:11800 -p 12800:12800 \
  -e TZ=Asia/Shanghai \
  -e SW_STORAGE=elasticsearch \
  -e SW_STORAGE_ES_CLUSTER_NODES=[ESofIP]:9200 \
  -e SW_ES_USER=elastic \
  -e SW_ES_PASSWORD="\"123456\"" \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

illustrate:

  • SW_STORAGE=elasticsearch: Specifies the use of ElasticSearch storage.
  • SW_STORAGE_ES_CLUSTER_NODES: Specifies the ElasticSearch service address, which can be the service name in the container (for example, elasticsearch:9200) or the IP address of the external service (for example, [ES's IP]:9200).
  • SW_ES_USER and SW_ES_PASSWORD: Authentication information used to connect to ElasticSearch.

Method 4: Start using the mount configuration file (custom configuration)

If you wish to use a custom configuration file, you can mount it into a container:

docker run -d \
  -p 11800:11800 \
  -p 12800:12800 \
  -v /opt/module/skywalking/config/:/skywalking/config/ \
  -e SW_STORAGE=elasticsearch \
  -e SW_STORAGE_ES_CLUSTER_NODES=elasticsearch:9200 \
  -e SW_ES_USER=elastic \
  -e SW_ES_PASSWORD="\"123456\"" \
  --link elasticsearch:elasticsearch \
  --name skywalking-oap \
  --restart always \
  apache/skywalking-oap-server:8.9.0

Environment variables:

  • You can use SW_STORAGE_ES_CLUSTER_NODES to specify the node address of the ElasticSearch cluster. If you are using the internal network of the container, you can use the name of the container instead of the IP address (for example, elasticsearch:9200).
  • SW_ES_USER and SW_ES_PASSWORD are used to authenticate information. If used in a production environment, make sure that password storage is secure and avoid exposing sensitive information through environment variables.

Mount the configuration file:

  • Use the -v option to mount the local configuration file into the container, so that you can flexibly configure various parameters of SkyWalking to avoid modifying environment variables every time.

Network connection:

  • Use --link elasticsearch:elasticsearch to connect to the network between Docker containers. However, it is recommended to use the Docker network instead of --link, because --link has been deprecated. You can connect between containers by creating a custom network.

3. Use MySQL storage (recommended✨)

  • Create a SkyWalking database in MySQL

    CREATE DATABASE skywalking CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    
  • Configuring MySQL Driver

    SkyWalking requires a MySQL JDBC driver to connect to the MySQL database. If you are usingMySQL 8, may need to manually transfermysql-connectorImport driver files intoskywalking-oapIn the container.

    Prepare the driver fileWillmysql-connector-java-8.0.Stack files anywhere on the server, for example/root

    Copy to Docker containerusedocker cpThe command passes the driver file into the SkyWalking OAP container:

    docker cp /root/mysql-connector-java-8.0. skywalking-oap:/skywalking/oap-libs
    

    Note that you should check whether the skywalking-oap container you are using is MySQL8 jar package. If there is mysql-connector-java-8, then skip this step

    # Check if there is an adaptive driverdocker exec -it skywalking-oap ls -l /skywalking/oap-libs
    
  • Start the SkyWalking OAP service and use MySQL to store data

    docker run \
      -d -p 11800:11800 -p 12800:12800 \
      -e SW_STORAGE=mysql \
      -e "SW_JDBC_URL=jdbc:mysql://mysql:3306/skywalking?useUnicode=true&characterEncoding=UTF-8&useSSL=false" \
      -e SW_DATA_SOURCE_USER=root \
      -e SW_DATA_SOURCE_PASSWORD=root \
      -v /opt/module/skywalking/config:/skywalking/config \
      -v /opt/module/skywalking/oap-libs:/skywalking/oap-libs \
      --link mysql:mysql \
      --name skywalking-oap \
      --restart always \
      apache/skywalking-oap-server:8.9.0
    

illustrate

  • SW_STORAGE=mysql: Specifies the use of MySQL storage.

  • SW_JDBC_URL: MySQL JDBC connection URL, format:

    jdbc:mysql://<MySQL service address>: <port>/<database name>?useUnicode=true&characterEncoding=UTF-8&useSSL=false

    In the examplemysqlIt is the Docker service name.3306It is the default port.

  • SW_DATA_SOURCE_USERandSW_DATA_SOURCE_PASSWORD: The user name and password of the MySQL database.

  • --link mysql:mysql: Through Docker--linkParameters to connect to the MySQL service (must make sure that the MySQL service is started and accessible).

Things to note

  • MySQL Address and Port: Make sure to replacemysql:3306For the actual MySQL address and port. If the MySQL service is running locally, it can be replaced withlocalhost:3306, if it is a remote database, it will be replaced with the corresponding remote address.
  • Create a database in advance: Before executing the startup command, make sure that it has been created in the MySQL database.skywalkingdatabase. You can adjust the database name and character set as needed.
  • MySQL version compatibility: Make sure that the version of MySQL you are using is compatible with SkyWalking OAP. It is recommended to use MySQL 5.7 or above.

4. Optional configuration: custom parameters or mount configuration files

  • Modify the JVM heap memory size

    docker run \
      -d -p 11800:11800 -p 12800:12800 \
      -e JAVA_OPTS="-Xmx2g" \
      --name skywalking-oap \
      --restart always \
      apache/skywalking-oap-server:8.9.0
    
  • Mount local configuration files

    Put the configuration file in/opt/module/skywalking/config/The path, the start command is as follows:

    docker run \
      -d -p 11800:11800 -p 12800:12800 \
      -v /opt/module/skywalking/config/:/skywalking/config/ \
      --name skywalking-oap \
      --restart always \
      apache/skywalking-oap-server:8.9.0
    

    Notice: Ensure that the mount path and configuration file content are correct.

Deploy SkyWalking UI

SkyWalking UI provides a web-based interface for visualizing telemetry data collected by OAP servers.

Method 1: Start the SkyWalking UI service through Docker

docker run \
  -d -p 8080:8080 \
  -e SW_OAP_ADDRESS=http://skywalking-oap:12800 \
  --link skywalking-oap:skywalking-oap \
  --name skywalking-ui \
  --restart always \
  apache/skywalking-ui:8.9.0

Browser access:http://<host IP>:8080

illustrate

  • The default access address of UI service ishttp://<host IP>:8080
  • The UI can monitor the operating status and metric data of the SkyWalking OAP service.
  • After startup, there may be fewer menus on the left, and you need to wait for the data to be reported before the full menu can be displayed.
  • When querying data, please confirm whether the time interval in the upper right corner is correct.

if8080The port is occupied, and it can be replaced here with other ports, for example:-p 28080:8080

Method 2: Start the SkyWalking UI service through Docker (using a custom network es-net

docker run \
  -d -p 8080:8080 \
  -e SW_OAP_ADDRESS=http://skywalking-oap:12800 \
  --net es-net \
  --name skywalking-ui \
  --restart always \
  apache/skywalking-ui:8.9.0

View the startup log

docker logs -f skywalking-oap
docker logs -f skywalking-ui

# View the last 20 lines of logdocker logs -f -t --tail 20 skywalking-oap
docker logs -f -t --tail 20 skywalking-ui

Enter the skywalking-oap and skywalking-ui containers

docker ps     # Check the running container and get the container id
# Enter the tomcat containerdocker exec -it [containerid] /bin/bash  # The container id in the middle is CONTAINER_IDdocker exec -it [containerid] /bin/sh
# -it means entry
docker exec -it skywalking-oap /bin/sh
docker exec -it skywalking-ui  /bin/sh
# Use command alias to enable ll commandscat &lt;&lt;EOF &gt;&gt; /etc/profile
alias ll='ls -l --color=tty'
alias grep='grep --color=auto'
EOF

source /etc/profile

View the firewall [Open Port]

# Check whether the port is openfirewall-cmd --query-port=8080/tcp
firewall-cmd --query-port=11800/tcp
firewall-cmd --query-port=12800/tcp

# Open port 80 and 443firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=11800/tcp
firewall-cmd --permanent --add-port=12800/tcp

# Remove portfirewall-cmd --permanent --remove-port=8080/tcp
firewall-cmd --permanent --remove-port=11800/tcp
firewall-cmd --permanent --remove-port=12800/tcp

# Restart the firewall (restart the firewall after modifying the configuration)firewall-cmd --reload

# Check out which ports have been developedfirewall-cmd --list-ports
firewall-cmd --zone=public --list-ports

test

#Server in browserhttp://Virtual machine IP: 8080

View log

View SkyWalking OAP Logs

docker logs -f skywalking-oap

View SkyWalking UI logs

docker logs -f skywalking-ui

Stop and delete the container

Stop and delete the OAP container

docker stop skywalking-oap
docker rm skywalking-oap

Stop and delete the UI container

docker stop skywalking-ui
docker rm skywalking-ui

in conclusion

After the above steps are completed, you have successfully configured the OAP server and UI for Apache SkyWalking. You can choose to use H2, Elasticsearch or MySQL as storage to monitor the system's operation through the SkyWalking UI.

This is the end of this article about the implementation example of Docker Skywalking. For more related content on Docker Skywalking, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!