Docker management with VS Code

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.

environment:

Windows 10 Home: 2004 VSCode: 1.49.2 Docker: 19.03.12

Remote Development installation

Launch VS Code, search for ** Remote Development ** with extensions and install

Creating an execution environment

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")

Create / start container

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.

Get out of the container

Click ** [> <] ** at the bottom left again, then select ** End Remote Connection ** Then you can get out of the container. The container also stops.

Re-enter the container

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.

Delete container

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

Docker extension

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.

Impressions

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.

reference

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

Docker management with VS Code
Getting Started with Docker with VS Code
Lombok with VS Code
Run VS Code on Docker
Format Ruby with VS Code
Hello World with VS Code!
Build Java development environment with WSL2 Docker VS Code
Spring Boot programming with VS Code
Java build with mac vs code
Summary of steps for developing in Docker container with VS Code
Try using Spring Boot with VS Code
Building a haskell environment with Docker + VS Code on Windows 10 Home
Using Gradle with VS Code, build Java → run
Create Spring Boot environment with Windows + VS Code
Try debugging a Java program with VS Code
Build a Java development environment with VS Code
Connect with VS Code from a Windows client to Docker on another server
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Docker
Disposable PHP with Docker
Install Composer with Docker
Build Java development environment with VS Code on Mac
Build ruby debug environment with VS Code of Windows 10
Introduce JavaFX 15 and do GUI development with VS Code
How to build Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Beginners create Spring Tools Suite environment with VS Code
Link Docker log to AWS CloudWatch and monitor in real time with VS Code
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a Java (Maven) project with VS Code and develop it on a Docker container
Pytorch execution environment with Docker
Use GDAL with Python with Docker
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Set up GitLab with docker
Create a VS Code Plugin.
Container management with ECS + CodePipline
Java web application development environment construction with VS Code (struts2)
Run Rails whenever with docker
Get started with DynamoDB with docker
Docker autostart settings with wsl2
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Build docker environment with WSL
Version control CocoaPods with Docker
Web application built with docker (1)
Try debugging natural language processing on Windows. with VS Code
Reduce verbose code with Lombok
I tried BIND with Docker
A memo to start Java programming with VS Code (2020-04 version)