I want to manage the development environment with Docker and code with VS Code For that purpose, I described the series of flow investigated and the operation of Docker on VS Code.
Windows 10 Home: 2004 VSCode: 1.49.2 Docker: 19.03.12
Launch VS Code, search for ** Remote Development ** with extensions and install
The file structure in development using Remote Development looks like this.
project
├ .devcontainer
├ devcontainer.json
└ Dockerfile
└ Contents
Located in the **. Devcontainer ** folder directly under the project It's like describing the settings related to the container in ** devcontainer.json ** and ** Dockerfile **. In the example, the Python environment is written in Refer here.
DockerPython
├.devcontainer
├ devcontainer.json
└ Dockerfile
├ requirements.txt
└ test.py
Dockerfile
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM python:3
devcontainer.json
{
"name": "Python 3",
"context": "..",
"dockerFile": "Dockerfile",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/bin/pylint"
},
"appPort": [ 9000 ],
"postCreateCommand": "pip install -r requirements.txt",
"extensions": ["ms-python.python"]
}
equirements.txt
scikit-learn
test.py
print("haloworld")
Click ** [> <] ** at the bottom left, then select ** Remote-Containers: Open Folder in Container… **, and ** Select the project described earlier (Docker Python in the example) ** to launch the container. (It will take some time) When the project is successfully launched, try running ** python test.py ** and ** pip freeze ** in your terminal.
/workspaces/DockerPython# python test.py
haloworld
/workspaces/DockerPython# pip freeze
joblib==0.16.0
numpy==1.19.2
scikit-learn==0.23.2
scipy==1.5.2
threadpoolctl==2.1.0
If it becomes as above, it is done properly.
Click ** [> <] ** at the bottom left again, then select ** End Remote Connection ** Then you can get out of the container. The container also stops.
Click ** Remote Explorer ** on the bar created when installing Remote Development Click the previous project from the list that appears after that. Click ** Open Contaner ** at the end of the file that appears after that. Click, and the container will restart and you can re-enter.
Click ** Remote Explorer ** after exiting the container Right-click on the project you want to delete and click ** Remove Container ** in the menu that appears. Then the container will be deleted
There is ** Docker ** as an extension of VS Code. Remote Development is sufficient to create an execution environment Docker ** responds well and displays images **, so for container management I think it's good to put it together.
If you use Remote Development, you can develop in Docker environment with VS Code It was nice to be able to operate Docker without typing commands.
https://qiita.com/Yuki_Oshima/items/d3b52c553387685460b0
https://paiza.hatenablog.com/entry/2019/07/08/VSCode%E3%81%A8Docker%E3%81%A7%E7%B0%A1%E5%8D%98%E3%81%AB%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%82%92%E6%A7%8B%E7%AF%89%EF%BC%86%E5%85%B1%E6%9C%89%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95
Recommended Posts