38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Docker.DotNet;
|
|
using MoonlightServers.Daemon.Extensions;
|
|
using MoonlightServers.Daemon.Services;
|
|
|
|
namespace MoonlightServers.Daemon.Abstractions;
|
|
|
|
public partial class Server
|
|
{
|
|
private async Task Create()
|
|
{
|
|
var dockerImageService = ServiceProvider.GetRequiredService<DockerImageService>();
|
|
|
|
// We call an external service for that, as we want to have a central management point of images
|
|
// for analytics and automatic deletion
|
|
await dockerImageService.Ensure(Configuration.DockerImage, async message => { await LogToConsole(message); });
|
|
|
|
await EnsureRuntimeVolume();
|
|
|
|
await LogToConsole("Creating container");
|
|
|
|
var dockerClient = ServiceProvider.GetRequiredService<DockerClient>();
|
|
|
|
var parameters = Configuration.ToRuntimeCreateParameters(
|
|
appConfiguration: AppConfiguration,
|
|
hostPath: RuntimeVolumePath,
|
|
containerName: RuntimeContainerName
|
|
);
|
|
|
|
var container = await dockerClient.Containers.CreateContainerAsync(parameters);
|
|
RuntimeContainerId = container.ID;
|
|
}
|
|
|
|
private async Task ReCreate()
|
|
{
|
|
await Destroy();
|
|
await Create();
|
|
}
|
|
} |