Skip to content

Commit f5c1aed

Browse files
committed
fix: docker auth
1 parent 390e755 commit f5c1aed

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

GZCTF/Services/DockerService.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DockerService : IContainerService
1313
private readonly ILogger<DockerService> logger;
1414
private readonly DockerConfig options;
1515
private readonly DockerClient dockerClient;
16+
private readonly AuthConfig? authConfig;
1617

1718
public DockerService(IOptions<DockerConfig> _options, IOptions<RegistryConfig> _registry, ILogger<DockerService> _logger)
1819
{
@@ -26,15 +27,13 @@ public DockerService(IOptions<DockerConfig> _options, IOptions<RegistryConfig> _
2627
dockerClient = cfg.CreateClient();
2728

2829
// Auth for registry
29-
if (!string.IsNullOrWhiteSpace(_registry.Value.ServerAddress)
30-
&& !string.IsNullOrWhiteSpace(_registry.Value.UserName)
31-
&& !string.IsNullOrWhiteSpace(_registry.Value.Password))
30+
if (!string.IsNullOrWhiteSpace(_registry.Value.UserName) && !string.IsNullOrWhiteSpace(_registry.Value.Password))
3231
{
33-
dockerClient.System.AuthenticateAsync(new() {
32+
authConfig = new AuthConfig()
33+
{
3434
Username = _registry.Value.UserName,
3535
Password = _registry.Value.Password,
36-
ServerAddress = _registry.Value.ServerAddress,
37-
}).Wait();
36+
};
3837
}
3938

4039
if (string.IsNullOrEmpty(this.options.Uri))
@@ -80,7 +79,7 @@ public DockerService(IOptions<DockerConfig> _options, IOptions<RegistryConfig> _
8079
await dockerClient.Images.CreateImageAsync(new()
8180
{
8281
FromImage = parameters.Image
83-
}, null, new Progress<JSONMessage>(msg =>
82+
}, authConfig, new Progress<JSONMessage>(msg =>
8483
{
8584
Console.WriteLine($"{msg.Status}|{msg.ProgressMessage}|{msg.ErrorMessage}");
8685
}), token);

GZCTF/appsettings.Template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"XorKey": "Q22yg09A91YWm1GsOf9VIMiw",
2424
"ContainerProvider": "Docker", // or K8s
2525
"DockerConfig": {
26-
"Uri": "",
26+
"Uri": "unix:///var/run/docker.sock",
2727
"PublicIP": "127.0.0.1"
2828
},
2929
"RegistryConfig": {

0 commit comments

Comments
 (0)