How-To: Mount a volume to a container
Categories:
This how-to guide will provide an overview of how to:
- Mount an ephemeral (short-lived) volume to a container
Prerequisites
Step 1: Define an app and a container
Begin by creating a file named app.bicep
with a Radius Application and container:
extension radius
param environment string
resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'myapp'
properties: {
environment: environment
}
}
resource container 'Applications.Core/containers@2023-10-01-preview' = {
name: 'mycontainer'
properties: {
application: app.id
container: {
image: 'ghcr.io/radius-project/samples/volumes:latest'
}
}
}
The samples/volumes
container will display the status and contents of the /tmpdir
directory within the container.
Step 2: Deploy the app and container
-
Deploy your app with the command:
rad deploy ./app.bicep
-
Once complete, port forward to your container with
rad resource expose
:rad resource expose containers mycontainer -a myapp --port 5000
-
Visit localhost:5000 in your browser. You should see a message warning that the directory
/tmpdir
does not exist:
Step 3: Add an ephemeral volume
Within the container.volume
property, add a new volume named temp
and configure it as a memory-backed ephemeral volume:
resource container 'Applications.Core/containers@2023-10-01-preview' = {
name: 'mycontainer'
properties: {
application: app.id
container: {
image: 'ghcr.io/radius-project/samples/volumes:latest'
volumes: {
tmp: {
kind: 'ephemeral'
managedStore: 'memory'
mountPath: '/tmpdir'
}
}
}
}
}
Redeploy your app and container
-
Redeploy your application to apply the new definition of your container:
rad deploy ./app.bicep
-
Once complete, port forward to your container with
rad resource expose
:rad resource expose containers mycontainer -a myapp --port 5000
-
Visit localhost:5000 in your browser. You should see the contents of
/tmpdir
, showing an empty directory. -
Press the
Create file
button to generate a new file in the directory, such astest.txt
: -
Done! You’ve now learned how to mount an ephemeral volume
Cleanup
-
Run the following command to delete your app and container:
rad app delete myapp
Feedback
Was this page helpful?
Glad to hear it! Please feel free to star our repo and join our Discord server to stay up to date with the project.
Sorry to hear that. If you would like to also contribute a suggestion visit and tell us how we can improve.