I've been trying to configure vscode so that when I click on that arrow shaped "run" button on the top right, vscode will then build a docker container if the image doesn't exist, and then run a python script in the docker container. I've been playing with the launch.json
and tasks.json
files however I was unsuccessful.This is what I have:launch.json:
{"version": "0.2.0","configurations": [ {"name": "Docker: Run Python Demo scripts","type": "docker","request": "launch","preLaunchTask": "docker-run","python": {"pathMappings": [ {"localRoot": "${workspaceFolder}","remoteRoot": "/opt/demos" } ],"projectType": "general","file": "/opt/demos/${relativeFile}" } } ]}
tasks.json
{"version": "2.0.0","tasks": [ {"type": "docker-build","label": "docker-build","platform": "python","dockerBuild": {"tag": "product-demo-scripts:latest","dockerfile": "${workspaceFolder}/Dockerfile","context": "${workspaceFolder}","pull": true } }, {"type": "docker-run","label": "docker-run","dependsOn": ["docker-build" ],"python": {"file": "/opt/demos/${relativeFile}" } } ]}
The goal of something like this is for someone who's not technical, they can just open vscode in the directory, click on the run button, and there you have it, the script runs successfully without them having to deal with docker.
From what I gathered from the docs, and from online sources. This is doable in debugging mode which worked for me, but that's not very presentable. \
I gathered that it doesn't work for regular execution.
I welcome anyone who was ever successful in achieving anything similar to what I described to contribute to this thread even if it's not with vscode. If you're reading this and reached this point then I wish a very good day.
Thank you !