When trying to develop and debug in container environment, in lieu of local machine
Purpose
- Environment consistency: Avoiding inconsistency due to different dependency/lib on local machine v in container
- Centralised dependency/lib management: Only one member needs to update the config (requirements.txt) in docker, and all other members will have access to updated dependency/libs automatically after git pull
- Convenience: Avoiding install/keep the same dependency/lib twice, i.e. on local machine and in container
Step-by-step guide
Note: This guide is based on VS Code. I've also tried IntelliJ IDEA (including PyCharm), but unfortunately it doesn't work on my laptop. If interested, see the link below under "Read more"
Step 1 Install extension and launch docker
On VS Code, make sure you've installed the extension Remote - Containers
After installing, you should see a button for this extension at the bottom-left corner of VS Code
Launch docker (you don't need to start the project container)
Step 2 Open container
Click the remote container button > Open folder in container > Open your working directory with Dockerfile inside the repo. For instance, for backend-offline subteam, choose backend-offline/dev-dashboard/dashboard-backend
You should now see a progress notification at the bottom-right corner. Note that this will take a minute (Only for the first time opening the working directory. Next time it would start very quickly).
When completed, you'll notice VS Code has deployed an image (name starting with vsc-) in your docker, and has inserted/started an container (name including some random scientist/mathematician).
Step 3 Run and debug in container environment
Click the button to the right of the container button, to choose your interpreter/SDK.
For python, click the area, which shows Python 3.6.8 64-bit above, and choose the interpreter Python 3.6.8 64-bit (it should be at /usr/local/bin/python)
Now you're ready to develop, run, and debug in container!
To exit, simple click the remote container button at the bottom-left corner of VS Code > Close Remote Connection.
{'_id': ObjectId('5f8771822ca2e28e9b5572df'), 'test_field': 'test_value'}
Linux-4.19.76-linuxkit-x86_64-with#1 SMP Tue May 26 11:42:35 UTC 2020
I've included a simple code in the repo of backend-offline subteam, at backend-offline/dev-dashboard/dashboard-backend/temp_container_test_run/container_test_run.py
If you run it, it should show in terminal the same output as above. Note the 2nd line Linux shows it's been run in container (not local machine of Mac OS/Windows)
Note
Everything you've coded is done in the same git repo.
If you choose to stop the container after finish coding, it's alright. Next time VS Code will automatically start it when you open the working directory as in steps above
Read more
Guide from VS code: https://code.visualstudio.com/docs/remote/create-dev-container
Guide from JetBrains (IntelliJ IDEA, PyCharm): https://www.jetbrains.com/help/idea/configuring-remote-python-sdks.html#Docker
There is no content with the specified labels




