This project aims to provide a tutorial on how to debug Golang applications inside Docker containers using both Docker and Docker Compose. if you want to know more detail you can visit the blog
- golang 1.16 or higher
- Docker
- Visual Studio Code
To get started with this project, please follow the below steps:
- Clone this repository to your local machine.
- Navigate to the project directory.
- Choose whether you use docker or docker-compose
To debug the Golang application inside the Docker container, follow the below steps:
- Navigate your terminal to this directory of repository
- Build image
docker build --file Dockerfile.debug --tag go-debugger-image .
- Run your image as container
docker run -d -p 3000:3000 -p 4000:4000 --name go-debugger-container go-debugger-image
- Run the "Go Containerized Debug" debugger in VS Code and set breakpoints in your code.
- Hit the URL that will trigger the function that you set a breakpoint in. For example, if you set a breakpoint at line 17-18, hit http://localhost:3000/test to start debugging.
- Navigate to the directory of the repository in your terminal.
- Run the "Go Containerized Debug" debugger in VS Code and set breakpoints in your code.
- Create and run the Docker container using the following command:
docker compose up
- Once the debugger is running, hit the URL that will trigger the function that you set a breakpoint in. For example, if you set a breakpoint at line 17-18, hit http://localhost:3000/test to start debugging with docker compose.