小编Pal*_*lBo的帖子

由于错误无法在 Ubuntu WSL 上运行 Docker 无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。docker 守护进程是否正在运行?

我在 Windows 10 机器上运行 WSL 2 (Ubuntu)。我使用官方 Docker 指南 ( https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository )在我的 Ubuntu 上安装了 Docker 。运行docker run hello-world会产生以下错误:docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

我尝试了以下步骤:

  1. 使用sudo docker...代替docker...
  2. 将用户添加到 docker 用户组 sudo usermod -aG docker $(whoami)
  3. sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &我在这个线程中找到的:https : //forums.docker.com/t/cannot-connect-to-the-docker-daemon-is-the-docker-daemon-running-on-this-host/8925/4

这些步骤都没有帮助。

docker version 产生这个输出:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu docker windows-subsystem-for-linux

24
推荐指数
2
解决办法
2万
查看次数

从 Postman 获取访问令牌:为“单页应用程序”客户端类型发布的令牌只能通过跨域请求兑换

我们最近使用 PKCE 为我们的应用程序从隐式授予流切换到授权代码流,现在我们在从 Postman 的 Azure AD 获取访问令牌时遇到了一些问题。该应用程序已在 Azure AD 中注册,我们基本上使用此处描述的 Postman 程序:https : //developer.mypurecloud.com/api/rest/postman/index.html#enable_authorization。调用https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize端点工作正常,但调用时出错https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token

"Error: Cound not complete OAuth 2.0 token request: "AADSTS9002327: Tokens issued for the 'Single-Page Application' client-type may only be redeemed via cross-origin requests.\r\nTrace ID: 8253f622-3425-4d0a-817c-281f86097300\r\nCorrelation ID: 9d84460f-ec02-4ace-af03-14d948e3d4ad\r\nTimestamp: 2020-04-15 14:02:03Z"
Run Code Online (Sandbox Code Playgroud)

这是访问令牌请求: 在此处输入图片说明

我们如何通过此授权流程使用 Postman 从 Azure AD 获取访问令牌?

authorization azure-active-directory postman

12
推荐指数
3
解决办法
7790
查看次数

Windows 终端 + oh-my-posh 不显示 git 状态

我已经在 Windows 终端中安装了 oh-my-posh 和 posh-git,但是它不会跟踪任何 git 更改,如图所示。不管我做了什么改变,它都只是显示这样,没有状态:

\n

在此输入图像描述

\n

我也尝试过不使用 posh-git,因为我认为 oh-my-posh 默认情况下具有此功能,但结果仍然相同。

\n

这是我的 oh-my-posh 主题:

\n
{\n  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",\n  "blocks": [\n    {\n      "alignment": "left",\n      "segments": [\n        {\n          "background": "#91ddff",\n          "foreground": "#100e23",\n          "powerline_symbol": "\xee\x82\xb0",\n          "properties": {\n            "folder_icon": "\xef\x84\x95",\n            "folder_separator_icon": " \xee\x82\xb1 ",\n            "home_icon": "\xef\x9f\x9b",\n            "style": "agnoster"\n          },\n          "style": "powerline",\n          "type": "path"\n        },\n        {\n          "background": "#95ffa4",\n          "foreground": "#193549",\n          "powerline_symbol": "\xee\x82\xb0",\n          "style": "powerline",\n          "type": "git"\n        },\n        {\n          "background": "#906cff",\n          "foreground": "#100e23",\n          "powerline_symbol": "\xee\x82\xb0",\n          "properties": {\n            "prefix": " \xee\x88\xb5 "\n          },\n …
Run Code Online (Sandbox Code Playgroud)

posh-git oh-my-zsh windows-terminal

8
推荐指数
1
解决办法
3444
查看次数

通过 Azure 管道将机密注入 Docker 映像

我在 Azure Devops 中有一个管道,用于构建一些图像并将其推送到 DockerHub。这些映像被推送到生产和开发环境,但也可用于拉取本地开发。对于 Azure 中生产和开发中的机密,我们仅使用密钥库和变量组。但是,我们还没有找到在本地工作时注入机密的良好解决方案。

例如,在 appsettings.json 中,我们有一个 ClientSecret 参数,用于针对 Azure AD 进行身份验证。我们如何在发布管道期间将此参数插入到 appsettings.json 中,并且以后不让其他人看到它?

一些建议包括在管道中使用文件转换,但这并不是最佳选择,因为我们实际上不想更改任何文件。另一个建议是在管道中使用 --build-arg ,但这些参数在docker history.

那么如何将秘密注入到 Docker 镜像中的 appsettings.json 中,并且这个秘密最好在任何地方都不可见呢?

azure docker azure-devops azure-pipelines

6
推荐指数
1
解决办法
3851
查看次数

使用 Maven 拆分单元和集成测试

我正在 Jenkins 中设置 CD 管道,我想分两个不同的步骤运行单元测试和集成测试。计划是让我的管道脚本看起来像这样,并让它们单独运行:

    stage('Unit tests') {
        steps {
            withMaven(maven: 'Maven 3.6.2') {
                sh 'mvn test -P coverage'
            }
        }
    }
    stage('Integration tests') {
        steps {
            withMaven(maven: 'Maven 3.6.2') {
                sh 'mvn test -P coverage'
            }
        }
Run Code Online (Sandbox Code Playgroud)

我已尝试使用此处所述的surefire插件: https: //dzone.com/articles/splitting-unit-and-integration-tests-using-maven-a,并且运行“mvn test”确实仅运行单元测试它应该,但是“mvn Integration-test”同时运行单元测试和集成测试。

我还尝试使用故障安全插件,如下所述:Maven 单独的单元测试和集成测试,但无论我输入哪个选项,“mvn verify”都会运行单元测试和集成测试。

如何使我的管道分两个不同的步骤执行单元测试和集成测试?

Pom 肯定会成功:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId> <!-- surefire plugin version managed by Spring Boot -->
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
            <executions>
                <execution>
                    <id>unit-tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skipTests>false</skipTests>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                    </configuration> …
Run Code Online (Sandbox Code Playgroud)

testing integration-testing unit-testing maven jenkins

5
推荐指数
1
解决办法
3582
查看次数

How to set environment variables in Dockerfile via Azure DevOps

In my projects Docker file I have some environment variables, like this:

ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Password
ENV MSSQL_PID=Developer
ENV MSSQL_TCP_PORT=1433 
Run Code Online (Sandbox Code Playgroud)

And I would like to pass the password here as an environment variable set in my pipeline.

In Azure DevOps I have two pipelines. One for building the solution and one for building and pushing docker images to DockerHub. There are options to set variables in both these pipelines: 在此处输入图片说明 在此处输入图片说明 我已经在两个管道中设置了密码,并在 Dockerfile 中编辑了我的密码,如下所示:

ENV SA_PASSWORD=$(SA_PASSWORD)
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。将环境变量从 Azure DevOps 传递到 Docker 映像的正确方法是什么? …

azure docker dockerfile azure-devops

5
推荐指数
2
解决办法
1万
查看次数

oh-my-posh 模块在 git 目录中运行缓慢

我在 PowerShell 中使用 oh-my-posh,它在 git 存储库中速度非常慢。在常规目录中,如果我按 Enter 键,则会立即出现新行。但是,如果我在 git repos 中按 Enter 键,则需要 1-2 秒才能出现新行。这是我的个人资料:

\n
{\n  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",\n  "blocks": [\n    {\n      "alignment": "left",\n      "segments": [\n        {\n          "background": "#91ddff",\n          "foreground": "#100e23",\n          "powerline_symbol": "\xee\x82\xb0",\n          "properties": {\n            "folder_icon": "\xef\x84\x95",\n            "folder_separator_icon": " \xee\x82\xb1 ",\n            "home_icon": "\xef\x9f\x9b",\n            "style": "agnoster"\n          },\n          "style": "powerline",\n          "type": "path"\n        },\n        {\n          "background": "#95ffa4",\n          "foreground": "#193549",\n          "powerline_symbol": "\xee\x82\xb0",\n          "style": "powerline",\n          "type": "git",\n          "properties": {\n            "display_status": true,\n            "display_stash_count": true,\n            "display_upstream_icon": true\n          }\n        },\n        {\n          "background": "#906cff",\n          "foreground": "#100e23",\n          "powerline_symbol": "\xee\x82\xb0",\n          "properties": …
Run Code Online (Sandbox Code Playgroud)

git oh-my-zsh

5
推荐指数
0
解决办法
1463
查看次数

如何从 Dockerfile 安装curl

我正在尝试在 Docker 容器上安装 curl 以在运行状况检查中使用它,但我似乎无法通过在 Dockerfile 中运行命令来安装它。这是我的 Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base
RUN apt-get update \
 && apt-get install -y curl
WORKDIR /app
COPY /Project.MyProject .
RUN dotnet publish -o /publish
WORKDIR /publish
ENTRYPOINT ["sh", "-c", "dotnet Project.MyProject.dll \"${DB_CONNECTION}\""]
Run Code Online (Sandbox Code Playgroud)

curl然后,当我首先从容器内部运行任何命令时docker exec it,它会告诉我curl not found。如果我apt-get update && apt-get install -y curl在容器启动并运行时运行,那么curl 安装得很好。如何通过在 Dockerfile 中运行命令来安装curl?我想避免在容器启动并运行后手动安装它。

curl docker dockerfile

5
推荐指数
1
解决办法
1万
查看次数

Jenkins无法发送电子邮件-需要验证

我有一台在Linux VM上运行的Jenkins服务器。我希望我的Jenkins每次开始构建时都给我发送电子邮件。我已经如下设置了电子邮件服务。由于我在Google帐户中使用2因子身份验证,因此我为Jenkins创建了一个应用密码,但仍然显示“需要身份验证”。我还安装了扩展电子邮件通知插件,并以完全相同的方式设置了相同的结果。有谁知道这里可能是什么问题?

电子邮件

jenkins

3
推荐指数
1
解决办法
162
查看次数

如何检查类是否属于某种类型,而忽略继承?

假设我有一个这样的父类和一个子类:

public class Parent{}
Run Code Online (Sandbox Code Playgroud)
public class Child : Parent{}
Run Code Online (Sandbox Code Playgroud)

现在在某些方法中,我想找到 type 的类Parent,但我对 type 的类不感兴趣Child。所以让我们说我做这样的事情:

var listOfParents = new List<Parent>();

foreach(item in someListOfItems)
{
   if(item is Parent)
   {
      listOfParents.Add(item);
   }

} 
Run Code Online (Sandbox Code Playgroud)

这将为我提供所有类型的类Parent,但也会提供所有类型的类Child,因为它实现了Parent. 我怎么能只检索类型的类Parent而忽略所有子类?我也想避免做很多if检查,if (item is Parent && !(item is Child)因为如果有很多类实现Parent.

c#

3
推荐指数
1
解决办法
44
查看次数

当应用程序在 Docker 容器中运行时,Swagger UI 给出 ​​404

在我的项目中,我在 Startup.cs 中设置了 Swagger 和 Swashbuckle:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "Example API", Version = "v1" });
            });

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });
Run Code Online (Sandbox Code Playgroud)

当我从 Visual Studio 运行我的应用程序时,我可以访问localhost:123456/swagger并获取 API 文档,就像它应该的那样。但是,当我通过 Docker 运行我的应用程序docker-compose up并访问时,example_IP/swagger我发现 404 未找到。example_IP用 Postman测试给了我预期的数据,所以 IP 或后端没有问题。我尝试了几个不同的 URL /swagger/swagger-ui.html等等,但没有区别。当在 Docker 容器中运行时,是否有任何特定的配置必须写入 Dockerfile 或其他地方才能访问 Swagger 文档?我正在通过 nginx 反向代理运行我的后端,不确定这是否重要。

Docker-compose 文件: …

.net c# nginx swagger docker

1
推荐指数
1
解决办法
2154
查看次数