-
|
Referencing a volume defined within When I run this var builder = DistributedApplication.CreateBuilder(args);
var compose = builder.AddDockerComposeEnvironment("compose")
.ConfigureComposeFile(file =>
{
file.Volumes.Add("redisVolumeKey", new()
{
Name = "redisVolumeName",
Driver = "local",
DriverOpts = new Dictionary<string, string>
{
["type"] = "none",
["o"] = "bind",
["device"] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), @".docker/volumes/mySolution/myVolume")
}
});
});
var cache = builder.AddRedis("redis").WithDataVolume("redisVolumeName", false);
builder.Build().Run();it generates services:
compose-dashboard:
# ...
redis:
# ...
volumes:
- type: "volume"
target: "/data"
source: "redisVolumeName" # <<
read_only: false
networks:
- "aspire"
networks:
aspire:
driver: "bridge"
volumes:
redisVolumeName: # <<
driver: "local"
redisVolumeKey: # <<
driver: "local"
driver_opts:
type: "none"
o: "bind"
device: "C:\\Users\\myUser\\.docker/volumes/mySolution/myVolume"if I change var cache = builder.AddRedis("redis").WithDataVolume("redisVolumeKey", false);it throws Any workaround you may suggest? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Theres an existing volume being added, you can reference it via:
|
Beta Was this translation helpful? Give feedback.
I guess I don't see the difference? ConfigureComposeFile gets called after aspire has translated the high level resource model to the low level docker compose model. When you add a voulme, it adds it to the service definition and to the compose file in the volumes section. ConfigureComposeFile gives you a chance to mutate this after the fact in a programmatic way.
You can't reference a volume defined in the aspire app model, defined in the compose file, but you can change the volume described in the aspire model before the compose file is written.
aspire model -> compose model -> file on disk.