Skip to content
Docs Try Aspire

DockerfileStage Methods

Class Methods 17 members
Represents a stage within a multi-stage Dockerfile.
Adds an ARG statement to define a build-time variable.
public class DockerfileStage
{
public DockerfileStage Arg(
string name)
{
// ...
}
}
name string The name of the build argument.
DockerfileStage The current stage.
Adds an ARG statement to define a build-time variable with a default value.
public class DockerfileStage
{
public DockerfileStage Arg(
string name,
string defaultValue)
{
// ...
}
}
name string The name of the build argument.
defaultValue string The default value for the build argument.
DockerfileStage The current stage.
Adds a CMD statement to set the default command.
public class DockerfileStage
{
public DockerfileStage Cmd(
string[] command)
{
// ...
}
}
command string[] The command to execute.
DockerfileStage The current stage.
Adds a comment to the Dockerfile. Multi-line comments are supported.
public class DockerfileStage
{
public DockerfileStage Comment(
string comment)
{
// ...
}
}
comment string The comment text. Can be single-line or multi-line.
DockerfileStage The current stage.
When a multi-line comment is provided, each line will be prefixed with '#'. Empty lines in multi-line comments are preserved as comment lines.
Adds a COPY statement to copy files from the build context.
public class DockerfileStage
{
public DockerfileStage Copy(
string source,
string destination)
{
// ...
}
}
source string The source path or pattern.
destination string The destination path.
DockerfileStage The current stage.
Adds a COPY statement to copy files with ownership change.
public class DockerfileStage
{
public DockerfileStage Copy(
string source,
string destination,
string chown)
{
// ...
}
}
source string The source path.
destination string The destination path.
chown string The ownership specification (e.g., "user:group").
DockerfileStage The current stage.
Adds a COPY statement to copy files from another stage.
public class DockerfileStage
{
public DockerfileStage CopyFrom(
string from,
string source,
string destination)
{
// ...
}
}
from string The source stage or image name.
source string The source path in the stage.
destination string The destination path.
DockerfileStage The current stage.
Adds a COPY statement to copy files from another stage with ownership change.
public class DockerfileStage
{
public DockerfileStage CopyFrom(
string stage,
string source,
string destination,
string chown)
{
// ...
}
}
stage string The source stage name.
source string The source path in the stage.
destination string The destination path.
chown string The ownership specification (e.g., "user:group").
DockerfileStage The current stage.
Adds an empty line to the Dockerfile for better readability.
public class DockerfileStage
{
public DockerfileStage EmptyLine()
{
// ...
}
}
DockerfileStage The current stage.
Adds an ENTRYPOINT statement to set the container entrypoint.
public class DockerfileStage
{
public DockerfileStage Entrypoint(
string[] command)
{
// ...
}
}
command string[] The entrypoint command to execute.
DockerfileStage The current stage.
Adds an ENV statement to set an environment variable.
public class DockerfileStage
{
public DockerfileStage Env(
string name,
string value)
{
// ...
}
}
name string The environment variable name.
value string The environment variable value.
DockerfileStage The current stage.
Adds an EXPOSE statement to expose a port.
public class DockerfileStage
{
public DockerfileStage Expose(
int port)
{
// ...
}
}
port int The port number to expose.
DockerfileStage The current stage.
Adds a RUN statement to execute a command.
public class DockerfileStage
{
public DockerfileStage Run(
string command)
{
// ...
}
}
command string The command to execute.
DockerfileStage The current stage.
Adds a RUN statement with mount options for BuildKit.
public class DockerfileStage
{
public DockerfileStage RunWithMounts(
string command,
params string[] mounts)
{
// ...
}
}
command string The command to execute.
mounts string[] The mount options (e.g., "type=cache,target=/root/.cache").
DockerfileStage The current stage.
Adds a USER statement to set the user for subsequent commands.
public class DockerfileStage
{
public DockerfileStage User(
string user)
{
// ...
}
}
user string The user name or UID.
DockerfileStage The current stage.
Adds a WORKDIR statement to set the working directory.
public class DockerfileStage
{
public DockerfileStage WorkDir(
string path)
{
// ...
}
}
path string The working directory path.
DockerfileStage The current stage.
WriteStatementAsync(StreamWriter, CancellationToken) Section titled WriteStatementAsync(StreamWriter, CancellationToken) override Task
Writes the statement to the specified writer.
public class DockerfileStage
{
public override Task WriteStatementAsync(
StreamWriter writer,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
writer StreamWriter The writer to write to.
cancellationToken CancellationToken optional A cancellation token.
Task A task representing the asynchronous write operation.