DEV Community

Cover image for VS Code with Python in Docker Quickstart
Serzhan Akhmetov
Serzhan Akhmetov

Posted on • Edited on

VS Code with Python in Docker Quickstart

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

  1. Install VS Code and the Remote Development extension pack
  2. 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
    
  3. ctrl+shift+p and start typing "remdev", select "Remote-Containers: Add Dev Container Configuration Files..."

  4. 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
  5. ctrl+shift+p and start typing "rerefo", select "Remote-Containers: Reopen Folder in Container"

  6. 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

Top comments (0)