vscode-docker

VS Code 的 docker 扩展。(Docker extension for VS Code.)

Github stars Tracking Chart

对 Visual Studio Code 的 docker 支持

Docker 扩展使您可以轻松地从 Visual Studio Code 构建、管理和部署容器化应用程序,例如:

  • 自动 Dockerfile,docker-compose.yml 和 .dockerignore 文件生成(按 F1 并搜索 Docker:将 Docker 文件添加到 Workspace)
  • 语法突出显示,悬停提示,docker-compose.yml 和 Dockerfile文 件的 IntelliSense(完成)
  • Dockerfile 文件的 Linting(错误和警告)
  • 命令面板(F1)集成最常见的 Docker 命令(例如docker build,docker push等)
  • 用于管理映像,运行容器和 Docker Hub 注册表的Explorer集成
  • 将 Docker Hub 和 Azure 容器注册表中的映像直接部署到 Azure App Service
  • 调试在 Linux Docker 容器中运行的 .NET Core 应用程序
  • 使用 docker 将引导您完成此扩展的许多功能

先决条件

要使用大部分 Docker 扩展功能,您需要在计算机上安装 Docker 并在系统路径上进行设置。

Linux

由于 VS Code 以非 root 用户身份运行,因此您还需要按照Linux的安装后步骤 “以非 root 用户身份管理 Docker”中的步骤,以便扩展能够访问 docker。

生成Docker文件

按 F1 并搜索 Docker:将 Docker 文件添加到 Workspace,为您的工作区类型生成 Dockerfile,docker-compose.yml,docker-compose.debug.yml 和 .dockerignore 件:

注意: 不为.NET Core应用程序生成 docker-compose.ymldocker-compose.debug.yml 文件。

编辑

Dockerfile and docker-compose.yml 文件的Rich IntelliSense(完成)。

Docker commands

许多最常见的 Docker 和 docker 组合命令都内置在 Command Palette 中 (F1).

Docker View

Docker 扩展为 VS Code 贡献了一个新的 Docker View。 在 View 中,Explorer 允许您查看和管理 Image、Containers 以及浏览 Docker Hub 注册表。 如果安装了 Azure 帐户扩展,您也可以浏览 Azure 容器注册表

右键单击上下文菜单可以快速访问命令选项板(F1)中的相同丰富命令集。

Docker Hub 登录

第一次展开 Docker Hub 节点时,系统会提示您登录 Docker Hub 帐户。

您的用户名和密码存储在操作系统凭证保险库中(例如 macOS keychain,Windows Credential Store),因此您无需每次都登录。 您可以通过右键单击Docker Hub 标签并选择注销来注销 Docker Hub。 这将从 OS 存储中删除凭据。

将映像部署到 Azure App Service

使用 Docker Explorer,您可以将 Docker Hub 注册表或 Azure 容器注册表中的映像直接部署到 Azure App Service实例,详见本入门指南。 此功能需要安装 Azure 帐户扩展和 Azure 订阅。 如果您没有 Azure 订阅,请立即注册一个30天的免费帐户,并获得 Azure Credits 的200美元,以试用任何 Azure 服务组合。

要登录 Azure,请按F1并搜索Azure登录。 然后,您将使用设备登录流程登录您的帐户。 单击“复制并打开”以打开默认浏览器。

Azure CLI

Microsoft将最新的 Azure CLI 发布为 Docker镜像。您可以通过Command Palette轻松启动运行CLI的容器(按F1并搜索 Docker:Azure CLI )。该扩展将运行一个交互式终端l附着在容器上。

容器启动后,系统会提示您登录到Azure帐户。从那里,使用 az account set 设置您要使用的订阅(您可以使用 az account list 查看所有订阅)。每次运行容器时都不需要登录,因为扩展卷将本地 $ HOME/.azure 文件夹装载到容器的 $ HOME/.azure 文件夹中。

安装

在 VS Code 中,按F1键并输入 ext install vscode-docker 。一旦安装了扩展程序,系统将提示您重新启动 Visual Studio 代码,该程序只需要(几乎)几秒钟。

当然,您需要在计算机上安装 Docker,以便从 Command Palette(F1,键入 Docker )中运行命令。

在 Linux 上运行命令

默认情况下,Docker 以 root 用户身份运行,要求其他用户使用 sudo 访问它。这个扩展并不承担 root 权限,因此您需要创建一个名为 docker 的 Unix 组并将用户添加到它。说明可以在这里找到:创建一个 Docker 组

连接到码头机器

扩展的默认连接是连接到本地docker守护进程。如果启动 Visual Studio 代码并将 DOCKER_HOST 环境变量设置为有效主机,则可以连接到 docker-machine 实例。

贡献

有几种方法可以为此存储库做出贡献:

  • 想法,功能要求和错误:我们愿意接受所有想法,并希望摆脱错误!使用问题部分报告新问题,提供您的想法或对现有线索作出贡献
  • 文档:发现拼写错误或措辞奇怪的句子?提交公关!
  • 代码:提供错误修复,功能或设计更改。

法律

在我们接受您的拉取请求之前,您需要签署贡献许可协议。所有你需要做的就是提交一个拉请求,然后PR将得到适当的标记(例如 cla-required , clanorequired , cla-signed , cla-already-signed )。如果您已经签署了协议,我们将继续审查公关,否则系统会告诉您如何签署 CLA。一旦您签署了 CLA,所有未来的 PR 将被标记为 cla-signed 。

遥测

这个扩展收集遥测数据,帮助我们为使用 Docker 和 VS Code 构建微服务应用程序建立更好的体验。我们只收集执行哪些命令的数据。我们不收集关于映像名称、路径等的任何信息。扩展程序尊重 telemetry.enableTelemetry 设置,您可以在常见问题解答

许可证

MIT

Overview

Name With Ownermicrosoft/vscode-docker
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 4)
PlatformWindows, Docker, Linux, Mac
License:Other
Release Count83
Last Release Namev1.29.0 (Posted on )
First Release Namev0.0.14 (Posted on 2015-10-30 21:10:49)
Created At2015-10-16 23:14:09
Pushed At2024-05-04 16:03:59
Last Commit At
Stargazers Count1.2k
Watchers Count101
Fork Count507
Commits Count1.6k
Has Issues Enabled
Issues Count2671
Issue Open Count74
Pull Requests Count1304
Pull Requests Open Count1
Pull Requests Close Count105
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Docker for Visual Studio Code (Preview)

Version Installs Build Status

The Docker extension makes it easy to build, manage and deploy containerized applications from Visual Studio Code. Check out the "Working with Docker" tutorial to get started.

Visit the wiki for additional information about the extension.

Prerequisites

Install Docker on your machine and add it to the system path.

On Linux, you must also follow the steps in “Manage Docker as a non-root user” from Post-installation steps for Linux because VS Code runs as a non-root user.

Features

  • Automatic Dockerfile, docker-compose.yml, and .dockerignore file generation (Open the command Palette, F1 by default, and search for Docker: Add Docker files to Workspace)
  • Syntax highlighting, hover tips, IntelliSense (completions) for docker-compose.yml and Dockerfile files
  • Linting (errors and warnings) for Dockerfile files
  • Command Palette (F1 by default) integration for the most common Docker commands (for example docker build, docker push, etc.)
  • Explorer integration for managing images, containers, registries, and more
  • Deploy images from a registry directly to Azure App Service
  • Debug .NET Core applications running in Linux Docker containers

Generating Docker Files

Press F1 (by default) and search for Docker: Add Docker Files to Workspace to generate Dockerfile, docker-compose.yml, docker-compose.debug.yml, and .dockerignore files for your workspace type:

dockerfile

Note: The docker-compose.yml and docker-compose.debug.yml files are not generated for all platforms, such as .NET Core applications, and are optional for Node.js applications.

Editing

Rich IntelliSense (completions) for Dockerfile and docker-compose.yml files:

IntelliSense for DockerFiles

Docker Commands

Many of the most common Docker commands are built right into the Command Palette (F1 by default):

commands

Docker View

The Docker extension contributes explorers to view and manage containers, images, registries, volumes, and networks. The right click context menus provide quick access to the same rich set of commands found in the Command Palette (F1 by default).

explorers

TIP: You can reorder the explorers by clicking and dragging on the explorer title. You can also hide the entire view by right clicking on the Docker icon or hide individual explorers by right clicking on the explorer title.

hideView hideExplorer

Debugging in Containers

With the Docker extension installed, you can easily debug .NET Core and Node.js apps within a container. Debugging support is enabled automatically when you dockerize your code with Docker: Add Docker Files to Workspace. To enable debugging for code that's already dockerized, open the Command Palette (F1 by default) and do Docker: Initialize for Docker Debugging.

debugging

Tasks

Use Visual Studio Code's tasks to build and launch Docker containers with custom settings like ports, volumes, networks, etc.

tasks

Registries

The first time you expand the registries explorer you'll be prompted to connect a registry. This will prompt you for credentials based on your provider (Azure, Docker Hub, etc.). These credentials will be stored in your operating system credentials vault (for example macOS keychain, Windows Credential Store) so that you don't need to sign in every time. You can right click on a registry provider to disconnect it and remove credentials from the OS store.

NOTE: Azure leverages the Azure Account Extension instead of storing Docker-specific credentials. After connecting Azure, you will be prompted separately to install that extension and/or sign in.

Deploy images to Azure App Service

With the Docker Explorer you can deploy images from Docker Hub Registries or Azure Container Registries directly to an Azure App Service instance. Check out this tutorial to get started.

Azure CLI

Microsoft ships the latest Azure CLI as a Docker image. You can easily launch a container running the CLI from the Command Palette (press F1 by default and search for Docker Images: Run Azure CLI). The extension will then run an interactive terminal attached to the container.

After the container is started, you will be prompted to sign in to your Azure account. From there, set the subscription you want to work with using az account set (you can see all of your subscriptions with az account list). You do not need to sign in every time you run the container because the extension volume mounts the local $HOME/.azure folder to the container's $HOME/.azure folder.

Connect to docker-machine

The default behavior of the extension is to connect to the local Docker daemon. You can connect to a docker-machine instance if you launch Visual Studio Code and have the Docker environment variables set in your environment or through the following VS Code settings: docker.host, docker.certPath, docker.tlsVerify, and docker.machineName.

Contributing

There are a couple of ways you can contribute to this repo:

  • Ideas, feature requests, and bugs: We are open to all ideas and we want to get rid of bugs! Use the Issues section to either report a new issue, provide your ideas or contribute to existing threads.
  • Documentation: Found a typo or strangely worded sentences? Submit a PR!
  • Code: Contribute bug fixes, features, or design changes:
    • Clone the repository locally and open in VS Code.
    • Install TSLint for Visual Studio Code.
    • Open the terminal (CTRL+ ` by default) and run npm install.
    • To build, open the Command Palette (F1 by default) and type in Tasks: Run Build Task.
    • Debug: press F5 (by default) to start debugging the extension.

Before we can accept your pull request you will need to sign a Contribution License Agreement. All you need to do is to submit a pull request, then the PR will get appropriately labelled (e.g. cla-required, cla-norequired, cla-signed, cla-already-signed). If you already signed the agreement we will continue with reviewing the PR, otherwise system will tell you how you can sign the CLA. Once you sign the CLA all future PR's will be labeled as cla-signed.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Telemetry

VS Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you don’t wish to send usage data to Microsoft, you can set the telemetry.enableTelemetry setting to false. Learn more in our FAQ.

License

MIT

To the top