Skip to content

Instantly share code, notes, and snippets.

@fcallejon
Last active March 12, 2019 08:53
Show Gist options
  • Save fcallejon/0e2508eadeba7cf4715430e7beaa7d77 to your computer and use it in GitHub Desktop.
Save fcallejon/0e2508eadeba7cf4715430e7beaa7d77 to your computer and use it in GitHub Desktop.
Some VSCode tasks and launch settings to ease docker usage

How to use this

Setup VS Code

  • Copy task.json, launch.json to your .vscode folder or copy the content into the file you already have.
  • Adapt your Dockerfile to be able to build in debug mode as in this one.
  • Run the task Install VSDbg using command palette. (CTRL+SHIFT+P or ⌘+⇧+P)

Debug

The default build task is StartDocker-Debug-Local which will start all the services in Docker with the exception of Service3. You will need to launch .NET Core Launch (Service3).

You can also start everything in Docer and debug it there using the tasks StartDocker-Debug and the launching Attach to Service3 in Docker.

Other tasks

  • StopDocker will start all the services in docker.
  • Restart Docker Services will restart the composer services.
  • build will just build Service3.
  • Docker Service Logs will open a terminal showing the logs (using -f) of a given service defined in the input service at the botton of tasks.json
version: '3.4'
services:
# https://hub.docker.com/r/hlebalbau/kafka-manager
# Just handy to have a Kafka Manager in dev
kafka_manager:
image: hlebalbau/kafka-manager:stable
ports:
- "9000:9000"
environment:
ZK_HOSTS: "service1:2181"
APPLICATION_SECRET: "Search2020"
command: -Dpidfile.path=/dev/null
depends_on:
- service1
networks:
- networkname
service3:
build:
context: ./Service3
dockerfile: Dockerfile
args:
buildconfig: Debug
image: ${REPO}/service3-debug:${TAG}
# Map both vsdbg and src folders
volumes:
- .\Service3:/app
- .\vsdbg:/vsdbg
environment:
- ASPNETCORE_ENVIRONMENT=Docker
networks:
- networkname
version: '3.4'
services:
# prevent docker-compose to create anything that can
# stop our local version of the service to work
service3:
image: hello-world
version: '3.4'
services:
service1:
image: 'bitnami/zookeeper:3.4.13'
ports:
- '2181:2181'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
networks:
- networkname
service2:
image: 'bitnami/kafka:1.1.1'
depends_on:
- service1
ports:
- '9092:9092'
environment:
- KAFKA_ZOOKEEPER_CONNECT=service1:2181
- ALLOW_PLAINTEXT_LISTENER=yes
networks:
- networkname
service3:
build:
context: .
dockerfile: Service3/Dockerfile
image: ${REPO}/service3:${TAG}
networks:
- networkname
environment:
- ASPNETCORE_ENVIRONMENT=Docker
ports:
- "3000:80"
depends_on:
- service2
networks:
networkname:
FROM microsoft/dotnet:2.2-sdk as build
ARG buildconfig
WORKDIR /app
COPY Service3.csproj .
RUN dotnet restore
COPY . .
RUN if [ "${buildconfig}" = "Debug" ]; then \
dotnet publish -o /publish -c Debug && \
echo "IN DEBUG MODE!!"; \
else \
dotnet publish -o /publish -c Release; \
fi
FROM microsoft/dotnet:2.2-aspnetcore-runtime
WORKDIR /publish
COPY --from=build /publish .
ENV DEBIAN_FRONTEND teletype
ENTRYPOINT [ "dotnet", "Service3.dll" ]
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (Service3)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-Service3",
"program": "${workspaceFolder}/Service3/bin/Debug/netcoreapp2.2/Service3.dll",
"args": [],
"cwd": "${workspaceFolder}/Service3",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
},
{
"name": "Attach to Service3 in Docker",
"type": "coreclr",
"request": "attach",
"sourceFileMap": {
"/app": "${workspaceFolder}/Service3"
},
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"debuggerPath": "/vsdbg/vsdbg",
"pipeProgram": "docker",
"pipeCwd": "${workspaceFolder}/Service3",
"quoteArgs": false,
"pipeArgs": [
"exec",
"-i",
"[DOCKER_COMPOSE_PREFIX_HERE]_service3_1"
]
}
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": {
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Service3/Service3.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "Install VSDbg",
"command": "powershell",
"type": "process",
"args": [
"-NonInteractive",
"-NoProfile",
"-WindowStyle",
"Hidden",
"-File",
"${workspaceFolder}\\GetVsDbg.ps1"
],
"problemMatcher":[]
},
{
"type": "shell",
"label": "Restart Docker Services",
"command": "docker-compose",
"args": [
"restart",
"${input:service}"
]
},
{
"label": "StopDocker",
"type": "shell",
"command": "docker-compose",
"args": [
"-f",
"docker-compose.yml",
"-f",
"docker-compose.dev.yml",
"down"
],
"group": "build",
"problemMatcher": []
},
{
"label": "StartDocker",
"type": "shell",
"command": "docker-compose",
"args": [
"-f",
"docker-compose.yml",
"-p",
"[DOCKER_COMPOSE_PREFIX_HERE]",
"up",
"-d",
"--build"
],
"group": "build",
"problemMatcher": []
},
{
"label": "StartDocker-Debug",
"type": "shell",
"command": "docker-compose",
"args": [
"-f",
"docker-compose.yml",
"-f",
"docker-compose.dev.yml",
"-p",
"[DOCKER_COMPOSE_PREFIX_HERE]",
"up",
"-d",
"--remove-orphans",
"--force-recreate",
"--build"
],
"group": "build",
"problemMatcher": []
},
{
"label": "StartDocker-Debug-Local",
"type": "shell",
"command": "docker-compose",
"args": [
"-f",
"docker-compose.yml",
"-f",
"docker-compose.dev.yml",
"-f",
"docker-compose.local.yml",
"-p",
"[DOCKER_COMPOSE_PREFIX_HERE]",
"up",
"-d",
"--remove-orphans",
"--force-recreate",
"--build"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"type": "process",
"label": "Docker Service Logs",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"showReuseMessage": false
},
"command": "docker",
"args": [
"logs",
"-f",
"[DOCKER_COMPOSE_PREFIX_HERE]_${input:service}_1"
],
"problemMatcher": []
}
],
// change the options below to reflect your services
"inputs": [
{
"id": "service",
"type": "pickString",
"description": "pick the service",
"options": [
"service1",
"service2",
"service3",
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment