lxc is a command-line tool in Linux used to manage Linux containers. The tool communicates with a container manager service, such as lxd, using the lxd REST API. Containers are isolated environments that allow you to run applications and services in a contained, isolated environment within a host operating system.
The lxc command provides a simple and convenient way to manage containers, including:
- Launching new containers
- Stopping and starting existing containers
- Displaying information about containers
- Copying containers
- Moving containers between hosts And more.
The lxc command can be used to manage containers on a local host or on remote servers. The name of a remote server can be prefixed to container names or patterns to specify the target server for operations. This allows you to manage containers on multiple servers from a single command-line interface.
The lxc command is a powerful tool for managing containers, making it easy to launch and manage isolated environments for applications and services. The integration with the lxd REST API allows for a flexible, scalable, and secure way to manage containers in Linux.
lxc Command Examples
1. List local containers matching a string. Omit the string to list all local containers:
# lxc list match_string
2. List images matching a string. Omit the string to list all images:
# lxc image list [remote:]match_string
3. Create a new container from an image:
# lxc init [remote:]image container
4. Start a container:
# lxc start [remote:]container
5. Stop a container:
# lxc stop [remote:]container
6. Show detailed info about a container:
# lxc info [remote:]container
7. Take a snapshot of a container:
# lxc snapshot [remote:]container snapshot
8. Execute a specific command inside a container:
# lxc exec [remote:]container command
lxc profile Command Examples
1. List all available profiles:
# lxc profile list
2. Show the configuration of a specific profile:
# lxc profile show profile_name
3. Edit a specific profile in the default editor:
# lxc profile edit profile_name
4. Edit a specific profile importing the configuration values from a file:
# lxc profile edit profile_name < config.yaml
5. Launch a new container with specific profiles:
# lxc launch container_image container_name --profile profile1 --profile profile2
6. Change the profiles of a running container:
# lxc profile assign container_name profile1,profile2
lxc network Command Examples
1. List all available networks:
# lxc network list
2. Show the configuration of a specific network:
# lxc network show network_name
3. Add a running instance to a specific network:
# lxc network attach network_name container_name
4. Create a new managed network:
# lxc network create network_name
5. Set a bridge interface of a specific network:
# lxc network set network_name bridge.external_interfaces eth0
6. Disable NAT for a specific network:
# lxc network set network_name ipv4.nat false