You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/create_docker_container.md
+42-9Lines changed: 42 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,35 +60,65 @@ _ = new ContainerBuilder("mcr.microsoft.com/dotnet/aspnet:10.0")
60
60
61
61
## Copying directories or files to the container
62
62
63
-
Sometimes it is necessary to copy files into the container to configure the services running inside the container in advance, like the `appsettings.json` or an SSL certificate. The container builder API provides a member `WithResourceMapping(string, string)`, including several overloads to copy directories or individual files to a container's directory.
63
+
Sometimes it is necessary to copy files into the container to configure the services running inside the container in advance, like the `appsettings.json` or an SSL certificate. The container builder API provides `WithResourceMapping(...)` overloads that support strongly typed source and target paths via `FilePath` and `DirectoryPath`.
// Copy 'appsettings.Container.json' to '/app/appsettings.json'.
79
+
.WithResourceMapping(
80
+
FilePath.Of("appsettings.Container.json"),
81
+
FilePath.Of("/app/appsettings.json"));
76
82
```
77
83
78
-
Another overloaded member of the container builder API allows you to copy the contents of a byte array to a specific file path within the container. This can be useful when you already have the file content stored in memory or when you need to dynamically generate the file content before copying it.
84
+
You can also copy the contents of a byte array to a specific file path within the container. This can be useful when you already have the file content stored in memory or when you need to dynamically generate the file content before copying it.
For remote sources, you can copy a file from a URL to a target directory or file before the container starts.
94
+
95
+
=== "Copying to a directory"
96
+
```csharp
97
+
_ = new ContainerBuilder("alpine:3.20.0")
98
+
.WithResourceMapping(
99
+
new Uri("https://localhost:8080/appsettings.json"),
100
+
DirectoryPath.Of("/app/"));
101
+
```
102
+
103
+
=== "Copying to a file"
104
+
```csharp
105
+
_ = new ContainerBuilder("alpine:3.20.0")
106
+
.WithResourceMapping(
107
+
new Uri("https://localhost:8080/appsettings.json"),
108
+
FilePath.Of("/app/appsettings.json"));
109
+
```
110
+
85
111
### Specifying file ownership
86
112
87
113
When copying files into a container, you can specify the user ID (UID) and group ID (GID) to set the correct ownership of the copied files. This is particularly useful when the container runs as a non-root user or when specific file permissions are required for security or application functionality.
88
114
89
115
```csharp title="Copying a file with specific UID and GID"
The `Unix` class provides common permission configurations like `FileMode755` (read, write, execute for owner; read, execute for group and others). For individual permission combinations, you can use the `UnixFileModes` enumeration to create custom configurations.
.ThrowIf(argument =>!argument.Value.Validate(), _ =>thrownewArgumentException("The service configuration of the Azure Event Hubs Emulator is invalid."));
162
+
.ThrowIf(argument =>!argument.Value.Validate(), _ =>newArgumentException("The service configuration of the Azure Event Hubs Emulator is invalid."));
0 commit comments