Skip to content
DocsTry Aspire
DocsTry

DockerfileStage Methods

ClassMethods17 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)
{
// ...
}
}
namestringThe name of the build argument.
DockerfileStageThe 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)
{
// ...
}
}
namestringThe name of the build argument.
defaultValuestringThe default value for the build argument.
DockerfileStageThe current stage.
Adds a CMD statement to set the default command.
public class DockerfileStage
{
public DockerfileStage Cmd(
string[] command)
{
// ...
}
}
commandstring[]The command to execute.
DockerfileStageThe current stage.
Adds a comment to the Dockerfile. Multi-line comments are supported.
public class DockerfileStage
{
public DockerfileStage Comment(
string comment)
{
// ...
}
}
commentstringThe comment text. Can be single-line or multi-line.
DockerfileStageThe 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)
{
// ...
}
}
sourcestringThe source path or pattern.
destinationstringThe destination path.
DockerfileStageThe current stage.
Adds a COPY statement to copy files with ownership change.
public class DockerfileStage
{
public DockerfileStage Copy(
string source,
string destination,
string chown)
{
// ...
}
}
sourcestringThe source path.
destinationstringThe destination path.
chownstringThe ownership specification (e.g., "user:group").
DockerfileStageThe current stage.
Adds a COPY statement to copy files from another stage.
public class DockerfileStage
{
public DockerfileStage CopyFrom(
string from,
string source,
string destination)
{
// ...
}
}
fromstringThe source stage or image name.
sourcestringThe source path in the stage.
destinationstringThe destination path.
DockerfileStageThe 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)
{
// ...
}
}
stagestringThe source stage name.
sourcestringThe source path in the stage.
destinationstringThe destination path.
chownstringThe ownership specification (e.g., "user:group").
DockerfileStageThe current stage.
Adds an empty line to the Dockerfile for better readability.
public class DockerfileStage
{
public DockerfileStage EmptyLine()
{
// ...
}
}
DockerfileStageThe current stage.
Adds an ENTRYPOINT statement to set the container entrypoint.
public class DockerfileStage
{
public DockerfileStage Entrypoint(
string[] command)
{
// ...
}
}
commandstring[]The entrypoint command to execute.
DockerfileStageThe current stage.
Adds an ENV statement to set an environment variable.
public class DockerfileStage
{
public DockerfileStage Env(
string name,
string value)
{
// ...
}
}
namestringThe environment variable name.
valuestringThe environment variable value.
DockerfileStageThe current stage.
Adds an EXPOSE statement to expose a port.
public class DockerfileStage
{
public DockerfileStage Expose(
int port)
{
// ...
}
}
portintThe port number to expose.
DockerfileStageThe current stage.
Adds a RUN statement to execute a command.
public class DockerfileStage
{
public DockerfileStage Run(
string command)
{
// ...
}
}
commandstringThe command to execute.
DockerfileStageThe current stage.
Adds a RUN statement with mount options for BuildKit.
public class DockerfileStage
{
public DockerfileStage RunWithMounts(
string command,
params string[] mounts)
{
// ...
}
}
commandstringThe command to execute.
mountsstring[]The mount options (e.g., "type=cache,target=/root/.cache").
DockerfileStageThe current stage.
Adds a USER statement to set the user for subsequent commands.
public class DockerfileStage
{
public DockerfileStage User(
string user)
{
// ...
}
}
userstringThe user name or UID.
DockerfileStageThe current stage.
Adds a WORKDIR statement to set the working directory.
public class DockerfileStage
{
public DockerfileStage WorkDir(
string path)
{
// ...
}
}
pathstringThe working directory path.
DockerfileStageThe current stage.
WriteStatementAsync(StreamWriter, CancellationToken)Section titled WriteStatementAsync(StreamWriter, CancellationToken)overrideTask
Writes the statement to the specified writer.
public class DockerfileStage
{
public override Task WriteStatementAsync(
StreamWriter writer,
CancellationToken cancellationToken = default(CancellationToken))
{
// ...
}
}
writerStreamWriterThe writer to write to.
cancellationTokenCancellationTokenoptionalA cancellation token.
TaskA task representing the asynchronous write operation.