title: Remote debug with VSCode, go & nakama
body: <p>i have the following problem. I try to run a nakama gameserver in go with docker.
  For the debugging purposes i want to use delve.</p>
  <p>I am not really sure if i am proceeding right, so maybe my problem is actually a complete different. But i think my delve does not connect to the nakama build.</p>
  <p>What have i done so far?
  I created a new go project and put a bit code in the main.go. After that i created a Dockerfile and an docker-compose.yml.
  I think in one of these two files is the mistake.
  My Dockerfile looks like this:</p>
  <pre><code>FROM golang
  
  ENV GOPATH /home/marc/go_projects
  ENV PATH ${GOPATH}/bin:/usr/local/go/bin:$PATH
  
  RUN go install github.com/go-delve/delve/cmd/dlv@latest
  
  FROM heroiclabs/nakama-pluginbuilder:3.3.0 AS go-builder
  
  ENV GO111MODULE on
  ENV CGO_ENABLED 1
  
  WORKDIR $GOPATH/gamedev
  
  COPY go.mod .
  COPY main.go .
  COPY vendor/ vendor/
  
  RUN go build --trimpath --mod=vendor --buildmode=plugin -o ./backend.so
  
  FROM heroiclabs/nakama:3.3.0
  
  COPY --from=go-builder /backend/backend.so /nakama/data/modules/
  COPY local.yml /nakama/data/
  </code></pre>
  <p>An my docker-compose.yml</p>
  <pre><code>version: '3'
  services:
    postgres:
      container_name: postgres
      image: postgres:9.6-alpine
      environment:
        - POSTGRES_DB=nakama
        - POSTGRES_PASSWORD=localdb
      volumes:
        - data:/var/lib/postgresql/data
      expose:
        - &quot;8080&quot;
        - &quot;5432&quot;
      ports:
        - &quot;5432:5432&quot;
        - &quot;8080:8080&quot;
    nakama:
      container_name: nakama
      image: heroiclabs/nakama:3.12.0
      entrypoint:
        - &quot;/bin/sh&quot;
        - &quot;-ecx&quot;
        - &gt;
          /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &amp;&amp;
          exec /nakama/nakama --name nakama1 --database.address postgres:localdb@postgres:5432/nakama --logger.level DEBUG --session.token_expiry_sec 7200        
      restart: always
      links:
        - &quot;postgres:db&quot;
      depends_on:
        - postgres
      volumes:
        - ./:/nakama/data
      expose:
        - &quot;7349&quot;
        - &quot;7350&quot;
        - &quot;7351&quot;
        - &quot;2345&quot;
      ports:
        - &quot;2345:2345&quot;
        - &quot;7349:7349&quot;
        - &quot;7350:7350&quot;
        - &quot;7351:7351&quot;
      healthcheck:
        test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://localhost:7350/&quot;]
        interval: 10s
        timeout: 5s
        retries: 5
  volumes:
    data:
  </code></pre>
  <p>When i build and run the docker image, it runs with no complains. I can open the webinterface of nakama, so this is running fine.
  But when i try to connect the debugger, it looks like he create a succesfull connection but closes it right away.
  SO my launch.json config is the following:</p>
  <pre><code> &quot;name&quot;: &quot;Connect to server&quot;,
   &quot;type&quot;: &quot;go&quot;,
   &quot;request&quot;: &quot;attach&quot;,
   &quot;mode&quot;: &quot;remote&quot;,
   &quot;remotePath&quot;: &quot;/home/marc/go_projects/bin/dlv&quot;,
   &quot;port&quot;: 2345,
   &quot;host&quot;: &quot;127.0.0.1&quot;,
   &quot;trace&quot;: &quot;verbose&quot;
  </code></pre>
  <p>This is what i get in /tmp/vs-code-debug.txt:</p>
  <pre><code>[07:24:05.882 UTC] From client: initialize({&quot;clientID&quot;:&quot;vscode&quot;,&quot;clientName&quot;:&quot;Visual Studio Code&quot;,&quot;adapterID&quot;:&quot;go&quot;,&quot;pathFormat&quot;:&quot;path&quot;,&quot;linesStartAt1&quot;:true,&quot;columnsStartAt1&quot;:true,&quot;supportsVariableType&quot;:true,&quot;supportsVariablePaging&quot;:true,&quot;supportsRunInTerminalRequest&quot;:true,&quot;locale&quot;:&quot;de&quot;,&quot;supportsProgressReporting&quot;:true,&quot;supportsInvalidatedEvent&quot;:true,&quot;supportsMemoryReferences&quot;:true})
  [07:24:05.882 UTC] InitializeRequest
  [07:24:05.882 UTC] To client: {&quot;seq&quot;:0,&quot;type&quot;:&quot;response&quot;,&quot;request_seq&quot;:1,&quot;command&quot;:&quot;initialize&quot;,&quot;success&quot;:true,&quot;body&quot;:{&quot;supportsConditionalBreakpoints&quot;:true,&quot;supportsConfigurationDoneRequest&quot;:true,&quot;supportsSetVariable&quot;:true}}
  [07:24:05.883 UTC] InitializeResponse
  [07:24:05.883 UTC] From client: attach({&quot;name&quot;:&quot;Connect to server&quot;,&quot;type&quot;:&quot;go&quot;,&quot;request&quot;:&quot;attach&quot;,&quot;mode&quot;:&quot;remote&quot;,&quot;remotePath&quot;:&quot;/home/marc/go_projects/bin/dlv&quot;,&quot;port&quot;:2345,&quot;host&quot;:&quot;127.0.0.1&quot;,&quot;trace&quot;:&quot;verbose&quot;,&quot;__configurationTarget&quot;:5,&quot;packagePathToGoModPathMap&quot;:{&quot;/home/marc/go_projects/gamedev&quot;:&quot;/home/marc/go_projects/gamedev&quot;},&quot;debugAdapter&quot;:&quot;legacy&quot;,&quot;showRegisters&quot;:false,&quot;showGlobalVariables&quot;:false,&quot;substitutePath&quot;:[],&quot;showLog&quot;:false,&quot;logOutput&quot;:&quot;debugger&quot;,&quot;dlvFlags&quot;:[],&quot;hideSystemGoroutines&quot;:false,&quot;dlvLoadConfig&quot;:{&quot;followPointers&quot;:true,&quot;maxVariableRecurse&quot;:1,&quot;maxStringLen&quot;:64,&quot;maxArrayValues&quot;:64,&quot;maxStructFields&quot;:-1},&quot;cwd&quot;:&quot;/home/marc/go_projects/gamedev&quot;,&quot;dlvToolPath&quot;:&quot;/home/marc/go_projects/bin/dlv&quot;,&quot;env&quot;:{&quot;ELECTRON_RUN_AS_NODE&quot;:&quot;1&quot;,&quot;GJS_DEBUG_TOPICS&quot;:&quot;JS ERROR;JS LOG&quot;,&quot;USER&quot;:&quot;marc&quot;,&quot;SSH_AGENT_PID&quot;:&quot;1376&quot;,&quot;XDG_SESSION_TYPE&quot;:&quot;x11&quot;,&quot;SHLVL&quot;:&quot;0&quot;,&quot;HOME&quot;:&quot;/home/marc&quot;,&quot;DESKTOP_SESSION&quot;:&quot;ubuntu&quot;,&quot;GIO_LAUNCHED_DESKTOP_FILE&quot;:&quot;/usr/share/applications/code.desktop&quot;,&quot;GTK_MODULES&quot;:&quot;gail:atk-bridge&quot;,&quot;GNOME_SHELL_SESSION_MODE&quot;:&quot;ubuntu&quot;,&quot;MANAGERPID&quot;:&quot;1053&quot;,&quot;DBUS_SESSION_BUS_ADDRESS&quot;:&quot;unix:path=/run/user/1000/bus&quot;,&quot;GIO_LAUNCHED_DESKTOP_FILE_PID&quot;:&quot;6112&quot;,&quot;IM_CONFIG_PHASE&quot;:&quot;1&quot;,&quot;MANDATORY_PATH&quot;:&quot;/usr/share/gconf/ubuntu.mandatory.path&quot;,&quot;LOGNAME&quot;:&quot;marc&quot;,&quot;_&quot;:&quot;/usr/share/code/code&quot;,&quot;JOURNAL_STREAM&quot;:&quot;8:44286&quot;,&quot;DEFAULTS_PATH&quot;:&quot;/usr/share/gconf/ubuntu.default.path&quot;,&quot;XDG_SESSION_CLASS&quot;:&quot;user&quot;,&quot;USERNAME&quot;:&quot;marc&quot;,&quot;GNOME_DESKTOP_SESSION_ID&quot;:&quot;this-is-deprecated&quot;,&quot;WINDOWPATH&quot;:&quot;2&quot;,&quot;PATH&quot;:&quot;/home/marc/.nvm/versions/node/v17.8.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/usr/local/go/bin:/usr/local/go/bin&quot;,&quot;SESSION_MANAGER&quot;:&quot;local/mobile:@/tmp/.ICE-unix/1458,unix/mobile:/tmp/.ICE-unix/1458&quot;,&quot;INVOCATION_ID&quot;:&quot;fe605ca56aa646859602b81e264bf01b&quot;,&quot;XDG_RUNTIME_DIR&quot;:&quot;/run/user/1000&quot;,&quot;XDG_MENU_PREFIX&quot;:&quot;gnome-&quot;,&quot;DISPLAY&quot;:&quot;:0&quot;,&quot;LANG&quot;:&quot;de_DE.UTF-8&quot;,&quot;XDG_CURRENT_DESKTOP&quot;:&quot;Unity&quot;,&quot;XAUTHORITY&quot;:&quot;/run/user/1000/gdm/Xauthority&quot;,&quot;XDG_SESSION_DESKTOP&quot;:&quot;ubuntu&quot;,&quot;XMODIFIERS&quot;:&quot;@im=ibus&quot;,&quot;SSH_AUTH_SOCK&quot;:&quot;/run/user/1000/keyring/ssh&quot;,&quot;SHELL&quot;:&quot;/bin/bash&quot;,&quot;QT_ACCESSIBILITY&quot;:&quot;1&quot;,&quot;GDMSESSION&quot;:&quot;ubuntu&quot;,&quot;GPG_AGENT_INFO&quot;:&quot;/run/user/1000/gnupg/S.gpg-agent:0:1&quot;,&quot;GJS_DEBUG_OUTPUT&quot;:&quot;stderr&quot;,&quot;QT_IM_MODULE&quot;:&quot;ibus&quot;,&quot;PWD&quot;:&quot;/home/marc&quot;,&quot;XDG_DATA_DIRS&quot;:&quot;/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop&quot;,&quot;XDG_CONFIG_DIRS&quot;:&quot;/etc/xdg/xdg-ubuntu:/etc/xdg&quot;,&quot;_WSREP_START_POSITION&quot;:&quot;&quot;,&quot;CHROME_DESKTOP&quot;:&quot;code-url-handler.desktop&quot;,&quot;ORIGINAL_XDG_CURRENT_DESKTOP&quot;:&quot;ubuntu:GNOME&quot;,&quot;VSCODE_CWD&quot;:&quot;/home/marc&quot;,&quot;GDK_BACKEND&quot;:&quot;x11&quot;,&quot;VSCODE_NLS_CONFIG&quot;:&quot;{\&quot;locale\&quot;:\&quot;de\&quot;,\&quot;availableLanguages\&quot;:{\&quot;*\&quot;:\&quot;de\&quot;},\&quot;_languagePackId\&quot;:\&quot;b61d3f473b0358bc955527db7340fd23.de\&quot;,\&quot;_translationsConfigFile\&quot;:\&quot;/home/marc/.config/Code/clp/b61d3f473b0358bc955527db7340fd23.de/tcf.json\&quot;,\&quot;_cacheRoot\&quot;:\&quot;/home/marc/.config/Code/clp/b61d3f473b0358bc955527db7340fd23.de\&quot;,\&quot;_resolvedLanguagePackCoreLocation\&quot;:\&quot;/home/marc/.config/Code/clp/b61d3f473b0358bc955527db7340fd23.de/30d9c6cd9483b2cc586687151bcbcd635f373630\&quot;,\&quot;_corruptedFile\&quot;:\&quot;/home/marc/.config/Code/clp/b61d3f473b0358bc955527db7340fd23.de/corrupted.info\&quot;,\&quot;_languagePackSupport\&quot;:true}&quot;,&quot;VSCODE_CODE_CACHE_PATH&quot;:&quot;/home/marc/.config/Code/CachedData/30d9c6cd9483b2cc586687151bcbcd635f373630&quot;,&quot;VSCODE_IPC_HOOK&quot;:&quot;/run/user/1000/vscode-432c1660-1.68.1-main.sock&quot;,&quot;VSCODE_PID&quot;:&quot;6112&quot;,&quot;NVM_INC&quot;:&quot;/home/marc/.nvm/versions/node/v17.8.0/include/node&quot;,&quot;LS_COLORS&quot;:&quot;&quot;,&quot;NVM_DIR&quot;:&quot;/home/marc/.nvm&quot;,&quot;LESSCLOSE&quot;:&quot;/usr/bin/lesspipe %s %s&quot;,&quot;LESSOPEN&quot;:&quot;| /usr/bin/lesspipe %s&quot;,&quot;NVM_CD_FLAGS&quot;:&quot;&quot;,&quot;NVM_BIN&quot;:&quot;/home/marc/.nvm/versions/node/v17.8.0/bin&quot;,&quot;GOPATH&quot;:&quot;/home/marc/go_projects&quot;,&quot;VSCODE_AMD_ENTRYPOINT&quot;:&quot;vs/workbench/api/node/extensionHostProcess&quot;,&quot;VSCODE_PIPE_LOGGING&quot;:&quot;true&quot;,&quot;VSCODE_VERBOSE_LOGGING&quot;:&quot;true&quot;,&quot;VSCODE_LOG_NATIVE&quot;:&quot;false&quot;,&quot;VSCODE_HANDLES_UNCAUGHT_ERRORS&quot;:&quot;true&quot;,&quot;VSCODE_LOG_STACK&quot;:&quot;false&quot;,&quot;VSCODE_IPC_HOOK_EXTHOST&quot;:&quot;/run/user/1000/vscode-ipc-8cf508cc-d427-4616-b6b5-61d3c3e5d99f.sock&quot;,&quot;APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL&quot;:&quot;1&quot;,&quot;GOMODCACHE&quot;:&quot;/home/marc/go_projects/pkg/mod&quot;,&quot;GOPROXY&quot;:&quot;https://proxy.golang.org,direct&quot;},&quot;__sessionId&quot;:&quot;1893ab9e-5a19-45e7-8b39-46db079cdbe3&quot;})
  [07:24:05.883 UTC] AttachRequest
  [07:24:05.884 UTC] Start remote debugging: connecting 127.0.0.1:2345
  [07:24:06.191 UTC] To client: {&quot;seq&quot;:0,&quot;type&quot;:&quot;event&quot;,&quot;event&quot;:&quot;initialized&quot;}
  [07:24:06.192 UTC] InitializeEvent
  [07:24:06.192 UTC] To client: {&quot;seq&quot;:0,&quot;type&quot;:&quot;response&quot;,&quot;request_seq&quot;:2,&quot;command&quot;:&quot;attach&quot;,&quot;success&quot;:true}
  [07:24:06.194 UTC] [Error] Socket connection to remote was closed
  [07:24:06.194 UTC] Sending TerminatedEvent as delve is closed
  [07:24:06.194 UTC] To client: {&quot;seq&quot;:0,&quot;type&quot;:&quot;event&quot;,&quot;event&quot;:&quot;terminated&quot;}
  [07:24:06.201 UTC] From client: configurationDone(undefined)
  [07:24:06.201 UTC] ConfigurationDoneRequest
  [07:24:06.225 UTC] From client: disconnect({&quot;restart&quot;:false})
  [07:24:06.225 UTC] DisconnectRequest
  </code></pre>
  <p>I tried to change the remote path i the launch.json multiple times, try to math the paths in the docker files.
  Maybe i have to change the implementation of delve in docker, but tbh i dont really know how. I dont really find a good documentation on how to do this.</p>