You love VS Code? Get ready to love it even more!
Recently, a new extension pack has come out from the good folks at Microsoft that enables remote development! Not only SSH, but also using local containers with either single containers or multiple containers with docker-compose!
Steps
- Install VS Code and the Remote Development extension pack
-
Start a new project by opening a new directory with VS Code Insiders and create a requirements.txt file with the Python packages you wish to have, e.g.:
django==2.2.2
ctrl+shift+p and start typing "remdev", select "Remote-Containers: Add Dev Container Configuration Files..."
-
Search for "pypo" and select "Python 3 & PostgreSQL" as your environmet. This will create a .devcontainer folder with the files:
- devcontainer.json
- docker-compose.yml
- Dockerfile
- noop.txt
ctrl+shift+p and start typing "rerefo", select "Remote-Containers: Reopen Folder in Container"
Start coding ☕💻
A note on opening ports
So how do you open a port to your container? Easy! VS Code already knows which ports are open in your container.
Say you started your server with python manage.py runserver
, which would open a port on 127.0.0.1:8000 in your container. VS Code is aware of this and will give you the option to forward your system ports to that port.
Press ctrl+shift+p, search "port" and select "Remote-Containers: Forward Port from Container...". A list of open ports will come up, select port 8000.
Source Code
https://github.com/siaarzh/python-vscode-starter
References
- Container Remote Development with VS Code
- Django Tutorial part 1
Top comments (0)