Skip to content

Instantly share code, notes, and snippets.

@phillijw
Last active August 5, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillijw/69ad884928970bbd3b60658ac9c4c054 to your computer and use it in GitHub Desktop.
Save phillijw/69ad884928970bbd3b60658ac9c4c054 to your computer and use it in GitHub Desktop.
Getting diagnostic tools to work in swarm

Steps to test

  1. Build the Dockerfile as image dotnet-tools
    docker build -t dotnet-tools .
  2. Deploy the compose file as a stack
    docker stack deploy --compose-file docker-compose.yml demo
  3. Attach to the dotnet-tools container
    docker exec -it abc123 /bin/bash
  4. Run dotnet-dump
    /tools/dotnet-dump collect -p 1 -o /data/dump

This succeeds but I'm not sure what process it's actually dumping. Since I have two containers running in my stack, how do I get it to hit the one I want?

#File: sample/docker-compose.yml
version: '3.4'
services:
sample1:
image: mcr.microsoft.com/dotnet/core/samples:aspnetapp
volumes:
- diagnostics:/tmp
- data:/data
deploy:
mode: replicated
replicas: 1
sample2:
image: mcr.microsoft.com/dotnet/core/samples:aspnetapp
volumes:
- diagnostics:/tmp
- data:/data
deploy:
mode: replicated
replicas: 1
diagnostics:
image: dotnet-tools:latest
volumes:
- diagnostics:/tmp
- data:/data
tty: true # Keep the container alive
volumes:
diagnostics:
data:
#File: dotnet-tools/Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as tools
RUN dotnet tool install --tool-path /tools dotnet-trace
RUN dotnet tool install --tool-path /tools dotnet-dump
RUN dotnet tool install --tool-path /tools dotnet-counters
FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS runtime
COPY --from=tools /tools /tools
@phillijw
Copy link
Author

phillijw commented Aug 5, 2020

root@af20f0f2b791:/tmp# ls -la
total 12
drwxrwxrwt 3 root root 4096 Aug  4 20:59 .
drwxr-xr-x 1 root root 4096 Aug  4 20:55 ..
prwx------ 1 root root    0 Aug  4 20:55 clr-debug-pipe-1-273760178-in
prwx------ 1 root root    0 Aug  4 20:55 clr-debug-pipe-1-273760178-out
prwx------ 1 root root    0 Aug  4 20:55 clr-debug-pipe-1-273760243-in
prwx------ 1 root root    0 Aug  4 20:55 clr-debug-pipe-1-273760243-out
srw------- 1 root root    0 Aug  4 20:55 dotnet-diagnostic-1-273760178-socket
srw------- 1 root root    0 Aug  4 20:55 dotnet-diagnostic-1-273760243-socket
drwxr-xr-x 2 root root 4096 Aug  4 20:52 system-commandline-sentinel-files

The sockets appear to exist.

@phillijw
Copy link
Author

phillijw commented Aug 5, 2020

Am I using this incorrectly?

me@MBP tools % docker ps
CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS              PORTS                  NAMES
af20f0f2b791        mcr.microsoft.com/dotnet/core/samples:aspnetapp   "dotnet aspnetapp.dll"   22 hours ago        Up 22 hours                                demo_sample2.1.eu2wxwffxxpat5h94dxvssckf
b00c3e01e0cd        mcr.microsoft.com/dotnet/core/samples:aspnetapp   "dotnet aspnetapp.dll"   22 hours ago        Up 22 hours                                demo_sample1.1.fa1mqo7ks08q78sfjbmjzn8p6
85528a4ab4b5        dotnet-tools:latest                               "bash"                   23 hours ago        Up 23 hours                                demo_diagnostics.1.gnkxmzaxfioq38dqwijcw7lee
me@MBP tools % docker run --rm --pid container:af20 -v "diagnostics:/tmp" -v "/tmp/data:/data" --cap-add ALL --privileged -it dotnet-tools /tools/dotnet-dump ps

me@MBP tools % 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment