forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerRunArgsBuilder.cs
56 lines (48 loc) · 1.63 KB
/
DockerRunArgsBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Text;
namespace Microsoft.DotNet.Docker.Tests
{
internal class DockerRunArgsBuilder
{
private readonly StringBuilder _builder =
new StringBuilder();
private DockerRunArgsBuilder()
{
}
public static DockerRunArgsBuilder Create()
{
return new DockerRunArgsBuilder();
}
public string Build()
{
return _builder.ToString();
}
/// <summary>
/// Sets the named environment variable with the specified value.
/// </summary>
public DockerRunArgsBuilder EnvironmentVariable(string name, string value)
{
_builder.AppendFormat(CultureInfo.InvariantCulture, "-e {0}={1} ", name, value);
return this;
}
/// <summary>
/// Exposes the container port to an arbitrary port on the host.
/// </summary>
public DockerRunArgsBuilder ExposePort(int port)
{
_builder.AppendFormat(CultureInfo.InvariantCulture, "-p {0} ", port);
return this;
}
/// <summary>
/// Mounts a volume in the container at the specified path.
/// </summary>
public DockerRunArgsBuilder VolumeMount(string name, string path)
{
_builder.AppendFormat(CultureInfo.InvariantCulture, "-v {0}:{1} ", name, path);
return this;
}
}
}