项目结构
制作docker-compose.yml并在控制台输入命令:docker-compose up -d (说明:-d代表在后台运行;保证端口9200/9300/8080/11800/12800未被占用;docker-compose没有设置networkt会自动以当前目录生成(xxx_default),当前目录为skywalking即network=skywalking_default),即可完成skywalking的制作。
version: '2'
services:
elasticsearch:
image: elasticsearch:6.8.0
container_name: skywalking-es
restart: always
ports:
- 9200:9200
- 9300:9300
environment:
discovery.type: single-node
TZ: Asia/Shanghai
oap:
image: apache/skywalking-oap-server:6.1.0
container_name: skywalking-oap
depends_on:
- elasticsearch
links:
- elasticsearch
restart: always
#前边为外网端口号,后边为容器应用端口号
ports:
- 11800:11800
- 12800:12800
environment:
# 设置时区
TZ: Asia/Shanghai
ui:
image: apache/skywalking-ui:6.4.0
container_name: skywalking-ui
depends_on:
- oap
links:
- oap
restart: always
ports:
- 8080:8080
#设置环境,配置覆盖yml的配置
environment:
collector.ribbon.listOfServers: oap:12800
security.user.admin.password: 123456
检查是否正确启动elasticsearch和skywalking
制作Dockerfile生成基础镜像给java服务使用,控制台命令输入:docker build -t centos.skywalking.base:0.0.1 .
FROM centos:7
WORKDIR /app
RUN yum install -y wget && \
yum install -y java-1.8.0-openjdk
ADD http://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/6.4.0/apache-skywalking-apm-6.4.0.tar.gz /app
RUN tar -xf apache-skywalking-apm-6.4.0.tar.gz && \
mv apache-skywalking-apm-bin skywalking
RUN ls /app
java服务接入swalking(多个同理),Dockerfile制作并在控制台输入:
1、docker build -t test:0.0.1 .
2、docker run -it -d --net skywalking_default -p 9812:9812 test:0.0.1
FROM centos.skywalking.base:0.0.1
COPY /target/app.jar /app/app.jar
EXPOSE 9812
ENTRYPOINT java -javaagent:/app/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=xxxtest -Dskywalking.collector.backend_service=172.19.0.3:11800 -Dserver.port=9812 -jar app.jar
Dskywalking.agent.service_name=xxx 指定java服务名称
-Dserver.port=xxx 指定java服务启动端口
Dskywalking.collector.backend_service=xxx oap服务收集ip默认为127.0.0.1:11800
查看启动的oap服务容器的ip,命令:docker inspect skywalking-oap。以下的IPAddress即为oap服务ip