{"id":20619739,"url":"https://github.com/twtrubiks/docker-remote-interpreter","last_synced_at":"2025-04-15T12:02:36.273Z","repository":{"id":84518943,"uuid":"131669593","full_name":"twtrubiks/docker-remote-interpreter","owner":"twtrubiks","description":"Using Docker as a Remote Interpreter ( Pycharm )","archived":false,"fork":false,"pushed_at":"2018-05-01T03:52:37.000Z","size":6,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T19:53:44.397Z","etag":null,"topics":["docker","pycharm","remote-interpreter","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twtrubiks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-01T02:43:30.000Z","updated_at":"2023-07-24T12:20:11.000Z","dependencies_parsed_at":"2023-03-02T04:30:28.516Z","dependency_job_id":null,"html_url":"https://github.com/twtrubiks/docker-remote-interpreter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fdocker-remote-interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fdocker-remote-interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fdocker-remote-interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fdocker-remote-interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twtrubiks","download_url":"https://codeload.github.com/twtrubiks/docker-remote-interpreter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067779,"owners_count":21207395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","pycharm","remote-interpreter","tutorial"],"created_at":"2024-11-16T12:12:23.626Z","updated_at":"2025-04-15T12:02:36.259Z","avatar_url":"https://github.com/twtrubiks.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-remote-interpreter\n\n* [Youtube Tutorial - docker-remote-interpreter-using-pycharm](https://youtu.be/bOUGyitONQ0)\n\n## 前言\n\n這篇文章主要是要教大家如何使用 Pycharm remote interpreter ( Using Docker )，這邊需要注意的是，\n\n要使用此功能，你的 Pycharm 必須是 **Professional** 的版本。\n\n為什麼我會突然介紹這個呢？原因是之前我在 windows 上用 Anaconda 安裝套件 ( Channels ) 時，\n\n一直有問題，於是我就想說不然用 docker 來解決，當然同時也需要 debug 阿:weary:\n\n於是就有了這篇文章的教學:smiley:\n\n## 教學\n\n首先，要先對 docker 有一些基本的認識，如果你對 docker 非常的陌生，可以參考我之前寫的文章\n\n* [Docker 基本教學 - 從無到有 Docker-Beginners-Guide 教你用 Docker 建立 Django + PostgreSQL 📝](https://github.com/twtrubiks/docker-tutorial)\n\n基本上，這篇的範例就是用上面文章的範例下去教學的:smirk:\n\n我主要是參考  [Configuring Remote Interpreter via DockerCompose](https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter-1.html) 這篇文章，但步驟不一樣相同，接下來的教學，\n\n使用的環境是 Win10，如果你是 MAC 用戶，也是可以使用 ( 只是手邊目前沒有 MAC，但確定可以使用 ，方法大同小異 )。\n\n先設定，將  Expose daemon...  這個打勾\n\n![alt tag](https://i.imgur.com/R3ot2a9.png)\n\nFile -\u003e Settings ( 或是快捷鍵`Ctrl+Alt+S`) 設定以下參數\n\n![alt tag](https://i.imgur.com/mttgpFu.png)\n\n再找到 Project Interpreter，選擇 Add Remote\n\n![alt tag](https://i.imgur.com/zl63LUr.png)\n\n接下來，請選擇 Docker Compose (這邊使用 docker-compose 來建立環境 )，\n\n其他參數，理論上預設就會幫你帶入了，\n\n![alt tag](https://i.imgur.com/kaJF9bw.png)\n\n先來介紹一下資料夾內的東西，\n\n[Dockerfile](https://github.com/twtrubiks/docker-remote-interpreter/blob/master/Dockerfile)\n\n基本上就是將目錄底下的檔案複製到 docker 容器裡面以及安裝 [requirements.txt](https://github.com/twtrubiks/docker-remote-interpreter/blob/master/requirements.txt)。\n\n[docker-compose.yml](https://github.com/twtrubiks/docker-remote-interpreter/blob/master/docker-compose.yml)\n\n裡面也很簡單，就是一個 postgres database，然後一個 app 啟動 django。\n\ndocker_remote_interpreter/[settings.py](https://github.com/twtrubiks/docker-remote-interpreter/blob/master/docker_remote_interpreter/settings.py)\n\n`settings.py` 裡面必須設定兩個東西，第一個是 `ALLOWED_HOSTS` 這部分，\n\n```python\nALLOWED_HOSTS = [\"*\"]\n```\n\n( 這邊提醒一下大家，設定 `*` 只是為了測試方便而已 )。\n\n第二個部分是將你的 db 修改成 postgres\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql_psycopg2',\n        'NAME': 'postgres',\n        'USER': 'postgres',\n        'PASSWORD': 'password123',\n        'HOST': 'db',\n        'PORT': 5432,\n    }\n}\n```\n\n接下來就是等，可能需要等一小段時間 ( 尤其是第一次，先去泡杯咖啡吧:relaxed: )\n\n![alt tag](https://i.imgur.com/k3jVYKb.png)\n\n當他跑完之後，按 ok ，會看到下圖\n\n![alt tag](https://i.imgur.com/gFqUXDD.png)\n\n右下角\n\n![alt tag](https://i.imgur.com/d0WHzT1.png)\n\n等全部都執行完之後\n\n![alt tag](https://i.imgur.com/iWnjI7t.png)\n\n填入 `0.0.0.0`，以這個範例來講， port 就是 8000\n\n![alt tag](https://i.imgur.com/y82Dvo3.png)\n\n直接開始 debug\n\n![alt tag](https://i.imgur.com/YbsC8yt.png)\n\n啟動成功\n\n![alt tag](https://i.imgur.com/CSq5oOl.png)\n\n可以使用 `docker ps` 確認\n\n![alt tag](https://i.imgur.com/8zeSK9s.png)\n\n最後我們直接進去容器 migrate\n\n```cmd\npython manage.py makemigrations\npython manage.py migrate\n```\n\n![alt tag](https://i.imgur.com/CWJIHD6.png)\n\n直接瀏覽，[http://localhost:8000/](http://localhost:8000/) ( 有時候可能會是 [http://0.0.0.0:8000/](http://0.0.0.0:8000/)，要看你電腦的 host 設定 )\n\n![alt tag](https://i.imgur.com/A0kF1wt.png)\n\n觀看容器內的 log ( 我們的確有成功連線上 )\n\n![alt tag](https://i.imgur.com/HbejCAg.png)\n\n到這邊就完成了:smile:\n\n## 後記\n\n整體來看，相信大家應該會覺得用 Pycharm 設定 remote-interpreter 蠻簡單的，但他也有缺點，就是如果你今天\n\n需要增加一個套件，你的 docker 就需要重新 build。\n\n可能有人會問，有沒有 vscode 的 remote-interpreter 教學呢 ? 這是個好問題，我後來也有嘗試用 vscode 設定，但\n\n設定一直失敗，如果有人成功，麻煩可以再指點一下，我會把教學補進文章裡面:grin:\n\n## 執行環境\n\n* Python 3.6.4\n* Win10\n\n## Reference\n\n* [Configuring Remote Interpreter via DockerCompose](https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter-1.html)\n\n## Donation\n\n文章都是我自己研究內化後原創，如果有幫助到您，也想鼓勵我的話，歡迎請我喝一杯咖啡:laughing:\n\n![alt tag](https://i.imgur.com/LRct9xa.png)\n\n[贊助者付款](https://payment.opay.tw/Broadcaster/Donate/9E47FDEF85ABE383A0F5FC6A218606F8)\n\n## License\n\nMIT licens","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fdocker-remote-interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwtrubiks%2Fdocker-remote-interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fdocker-remote-interpreter/lists"}