LCX/LXD Cheatsheet – Snapshots

Container Information / List Snapshots for a Container
#lxd info CONTAINER-NAME --verbose

Create Snapshots
#lxc snapshot CONTAINER-NAME
#lxc snapshot CONTAINER-NAME

Restore Container from Snapshot
#lxc restore CONTAINER-NAME/CONTAINER-NAME

Rename / Move a Snapshot
lxc move CONTAINER-NAME/SNAPSHOT-NAME CONTAINER-NAME/NEW-SNAPSHOT-NAME

Create a Container from a Snapshot
lxc copy CONTAINER-NAME/SNAPSHOT-NAME NEW-CONTAINER-NAME

Delete a Snapshot
lxc delete CONTAINER-NAME/SNAPSHOT-NAME

Cloning
lxc copy SOURCE DESTINATION
lxc move OLD-CONTAINER-NAME NEW-CONTAINER-NAME

While the source container is running:-
lxc snapshot NODE:CONTAINER SNAPSHOT
lxc copy NODE:CONTAINER/SNAPSHOT NEW-CONTAINER

Managing Images
lxc image list #list local images
lxc launch IMAGE CONTAINER #lxc launch ubuntu:14.04
lxc publish CONTAINER --alias NEW-IMAGE-NAME #turn a container into an image
lxc publish CONTAINER/SNAPSHOT --alias NEW-IMAGE-NAME #turn a past container image into a new image
lxc image delete NAME #deleting images

Exporting a Container (stopping it)
#lxc list
#lxc publish CONTAINER --force --alias CONTAINER_`date -I` #use --force to have it stopped and restarted.
#lxc image list
#lxc image export CONTAINER_`date -I`
#ls
xxxxxxxxxxxxxxxxx.tar.gz

Exporting a Container (without stopping it)
#lxc list
#lxc snapshot container_name snapshot_name
#lxc publish container_name/snapshot_name --alias image_name
#lxc image list
#lxc image export CONTAINER_`date -I`
#ls
xxxxxxxxxxxxxxxxx.tar.gz

Importing a Container
#lxc image import xxxxxxxxxxxxxx.tar.gz --alias=test1
#lxc image list
#lxc launch test1 test2
#lxc exec test2 bash

Leave a Reply

Your email address will not be published. Required fields are marked *