正如标题所示,我有一个无法从主机端口绑定到容器端口的容器.我尝试搜索类似的问题,但是没有发现任何与在docker容器中使用dotnet watch相关的问题,因为微软推出了microsoft/dotnet
带有内置于sdk映像中的dotnet watch 的docker repo.
任何关于我做错的建议都非常感谢.
Dockerfile
FROM microsoft/dotnet:2.1.301-sdk as build
ENV DOTNET_USE_POLLING_FILE_WATCHER 1
WORKDIR /app
COPY . .
RUN dotnet restore
EXPOSE 5000-5001
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore"]
Run Code Online (Sandbox Code Playgroud)
泊坞窗,compose.yml
version: "3"
services:
esportapp:
container_name: esportapp
image: esportapp:dev
build:
context: .
dockerfile: Docker/dev.Dockerfile
volumes:
- esportapp.volume:/app
ports:
- "5000:5000"
- "5001:5001"
volumes:
esportapp.volume:
Run Code Online (Sandbox Code Playgroud)
完成错误:
esportapp | Hosting environment: Development
esportapp | Content root path: /app
esportapp | Now listening on: https://localhost:5001
esportapp | Now listening on: http://localhost:5000 …
Run Code Online (Sandbox Code Playgroud) 我已经用这样的打字稿设置了一个 redux thunk 函数:
export const fetchActivities = (): AppThunk => async dispatch => {
dispatch(fetchActivitiesRequest())
try {
const res = await fetch("/activities")
const body = await res.json()
dispatch(fetchActivitiesSuccess(body))
} catch (err) {
dispatch(fetchActivitiesError(err))
}
}
Run Code Online (Sandbox Code Playgroud)
AppThunk 只是从 ThunkAction 类型派生的类型,具有以下类型参数:
export type AppThunk<ReturnType = void> = ThunkAction<ReturnType, {}, null, Action<string>>
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试为我的操作设置单元测试时,以及当我尝试像这样分派 thunk 操作时:
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
const store = mockStore({ activities: [] })
store.dispatch(actions.fetchActivities())
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
Argument of type 'ThunkAction<void, {}, null, Action<string>>' is not assignable …
Run Code Online (Sandbox Code Playgroud) 我有一个.Net Core应用程序,我使用.AddMediatR
扩展来按照CQRS方法为我的命令和处理程序注册程序集.
在Startup.cs中的ConfigureServices中,我使用了官方包中的扩展方法,MediatR.Extensions.Microsoft.DependencyInjection
其中包含以下参数:
services.AddMediatR(typeof(AddEducationCommand).GetTypeInfo().Assembly);
Run Code Online (Sandbox Code Playgroud)
命令和命令处理程序类如下:
AddEducationCommand.cs
public class AddEducationCommand : IRequest<bool>
{
[DataMember]
public int UniversityId { get; set; }
[DataMember]
public int FacultyId { get; set; }
[DataMember]
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
AddEducationCommandHandler.cs
public class AddEducationCommandHandler : IRequestHandler<AddEducationCommand, bool>
{
private readonly IUniversityRepository _repository;
public AddEducationCommandHandler(IUniversityRepository repository)
{
_repository = repository;
}
public async Task<bool> Handle(AddEducationCommand command, CancellationToken cancellationToken)
{
var university = await _repository.GetAsync(command.UniversityId);
university.Faculties
.FirstOrDefault(f => f.Id == command.FacultyId) …
Run Code Online (Sandbox Code Playgroud) 我有一个多项目解决方案,我无法从主项目成功添加数据库迁移University.Application
。数据库上下文在程序集中定义University.Infrastructure
。
当尝试dotnet ef migrations add Initial
在 University.Application 项目目录中时,我收到以下错误:
Your target project 'University.Application' doesn't match your migrations assembly 'University.Infrastructure'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("University.Application")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" …
entity-framework-core asp.net-core entity-framework-migrations
我正在尝试创建一个 Dockerfile 和一个 docker-compose.yml 文件,以dotnet watch run
在多项目 ASP.Net Core 解决方案上运行。目标是让容器监视所有三个项目的变化。
我的解决方案结构是这样的:
Nc.Application
Nc.Domain
Nc.Infrastructure
docker-compose.yml
Run Code Online (Sandbox Code Playgroud)
Nc.Application
包含要运行的主项目,另外两个文件夹是主项目引用的.Net标准项目。Nc.Application
我在里面有一个文件夹,里面有Docker
我的 dockerfile。
Controllers
Docker
Development.Dockerfile
Properties
Program.cs
Startup.cs
...
Run Code Online (Sandbox Code Playgroud)
我的 Dockerfile 和 compose 文件包含以下内容:
开发.Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "http://0.0.0.0:5000" ]
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: '3'
services:
nc.api:
container_name: ncapi_dev
image: ncapi:dev
build:
context: ./Nc.Application
dockerfile: Docker/Development.Dockerfile
volumes:
- ncapi.volume:.
ports:
- "5000:5000"
- "5001:5001"
volumes:
ncapi.volume:
Run Code Online (Sandbox Code Playgroud)
当我尝试运行时docker-compose up
,出现以下错误:
ERROR: for …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个 SPA (React) 应用程序,我想使用 cookie 来实现身份验证来跟踪活动会话,并且仅在用户通过身份验证后才允许访问某些路由。
我想知道如何开发 SPA,遵循最佳实践,确保除非设置了会话 cookie,否则无法查看受保护的路由(需要用户身份验证的路由)。
我正在研究不同的身份验证解决方案,其中大多数似乎在成功身份验证后设置具有以下属性的 HTTP cookie:SameSite、Secure 和 HttpOnly。身份验证解决方案将与 SPA 位于同一域中,因此 SameSite 对我来说很有意义。该域具有 SSL 证书,因此通信将通过 HTTPS 进行,因此安全对我来说很有意义。
但是,由于 SPA 是 JavaScript,因此它无法访问 HttpOnly cookie,因此也无法访问会话 cookie。
我可以看到这个问题的一些可能的解决方案:
从身份验证服务成功进行身份验证后,将用户重定向到 NodeJS 应用程序的 /app 端点,然后该端点会验证浏览器发送的 cookie。如果 cookie 有效,则提供 SPA。如果没有,请重定向到身份验证服务登录屏幕。
我认为大多数 SSR Web 应用程序都使用这种方法。但是,由于这是 SPA,因此只需在为应用程序提供服务的顶级路由上完成即可。
我还没有对此进行深入研究,但如果可以的话,它将使 SPA 面临 XSS 攻击,这是我想避免的。
这两种方法中的任何一种都是正确的方法吗?我意识到有多种方法可以解决这个问题,但我怀疑存在解决这个问题的最佳实践,因为它在当今许多作为 SPA 开发的 Web 应用程序中很常见。
最后一个问题 - 关于 HttpOnly、Secure 和 SameSite cookie,我意识到 Chrome、Firefox、Safari 和 Edge 等浏览器会阻止人们创建具有这些属性的 cookie。但是,是否有人可以在流行的浏览器之外以某种方式创建具有这些属性的 cookie,从而访问需要用户完成身份验证过程的 Web …
我有 Kafka 作为容器运行,我想创建一个主题。
当我尝试以下命令时:
docker exec -it [container_id] /bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"/bin/kafka-topics.sh\": stat /bin/kafka-topics.sh: no such file or directory": unknown
Run Code Online (Sandbox Code Playgroud)
如何完成主题的创建?
我已经从以下 YAML 部署了 Microsoft 的标准 aspnet 应用程序:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: microservicesapp
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: aspnetapp
servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
name: aspnetapp
spec:
selector:
app: aspnetapp
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
name: aspnetapp
labels:
app: aspnetapp
spec:
containers:
- image: "mcr.microsoft.com/dotnet/core/samples:aspnetapp"
name: aspnetapp-image
ports:
- containerPort: 80
protocol: TCP
Run Code Online (Sandbox Code Playgroud)
当我调用与我的 AGW 资源关联的公共 IP 时,一切正常。但是,我想配置入口的路径,使其成为/test …
我有一个List<TestObj> ListOfTestObjs
类型
public class TestObj
{
public List<int> Ints;
}
Run Code Online (Sandbox Code Playgroud)
如果情况是给定的整数x出现n次,我如何执行返回列表中对象的Linq查询,如果不是则返回null?像这样的东西:
ListOfTestObjs.FirstOrDefault(l => l.Ints == x occurs 3 times in Ints)
Run Code Online (Sandbox Code Playgroud)
提前致谢
我的存储库中有以下方法。到目前为止,我相信返回的int只是一个指示操作是否成功的int。我希望int是成功执行后返回的id(即表的单列)。我该如何完成?
public async Task<int> AddNewGroup()
{
using(_connection)
{
_connection.Open();
var id = await _connection.ExecuteAsync("INSERT INTO groups").Single();
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下测试说明了我试图实现的一个简单示例(两个等效列表的比较):
[Fact]
public void Test()
{
// Arrange
var list1 = new List<IDomainEvent> { new BusinessCreatedDomainEvent { Name = "Microsoft" } };
var list2 = new List<IDomainEvent> { new BusinessCreatedDomainEvent { Name = "Microsoft" } };
// Act
// Assert
list1.Should().BeEquivalentTo(list2);
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,每个列表应该能够包含从IDomainEvent
界面派生的任意数量的不同类型的项目.测试目前失败.我怀疑它与Should().BeEquivalentTo
不适合比较运行时指定的类型有关.我如何配置此示例,以便测试通过?
目前测试结果如下:
[8/14/2018 5:21:26 PM Error] [xUnit.net 00:00:00.7909767] BusinessWrite.UnitTests.Infrastructure.EventStoreUnitTests.Test [FAIL]
[8/14/2018 5:21:26 PM Informational] [xUnit.net 00:00:00.7922005] System.InvalidOperationException : No members were found for comparison. Please specify some members to include in the comparison or …
Run Code Online (Sandbox Code Playgroud) 我遇到过显示输出并以 END 结束输出的命令行工具,如下所示:
arbitrary output..
~
~
~
~
~
~
~
~
~
~
~
~
(END)
Run Code Online (Sandbox Code Playgroud)
我的问题是,我无法使用Ctrl + Z
或Ctrl + C
我知道的任何其他命令组合来退出此操作,这意味着每次发生时我都必须关闭终端。
我如何停止像上面这样的输出,并返回到我在终端中的位置?
我已将 NuGet 包 (BuildingBlocks) 发布到 Github Packages。我使用 nuget.config 文件指定项目的 nuget 源以及包的凭据(故意用占位符替换凭据):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/<username>/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="<username>" />
<add key="ClearTextPassword" value="<password>" />
</github>
</packageSourceCredentials>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我在 Fedora 机器上本地运行 dotnet Restore 时,它工作正常。但是,当我尝试恢复从mcr.microsoft.com/dotnet/sdk
映像派生的 Docker 容器中的包时,恢复失败并出现以下错误:
Determining projects to restore...
/app/src/DocumentService.Application/DocumentService.Application.csproj : error NU1101: Unable to find package BuildingBlocks.Annotations. No packages exist with …
Run Code Online (Sandbox Code Playgroud) nuget nuget-package-restore .net-core asp.net-core dotnet-cli
asp.net-core ×5
docker ×3
c# ×2
.net-core ×1
apache-kafka ×1
autofac ×1
bash ×1
cookies ×1
dapper ×1
dockerfile ×1
dotnet-cli ×1
entity-framework-migrations ×1
kubernetes ×1
linq ×1
mediatr ×1
nuget ×1
react-redux ×1
redux ×1
redux-thunk ×1
terminal ×1
typescript ×1
xunit ×1