Install LXC Container on Linux System
Updated:
Installing LXC:
- Ubuntu/Debian System
- Centos System
Verify LXC Installation:
Enable LXC Service:
Create a New LXC Container:
- Replace
mycontainer
with the name of your container. - The
-t ubuntu
flag specifies an Ubuntu template.
If you get an error about missing images,
Update the template cache:
-d ubuntu
: Distribution likecentos
,debian
,busybox
-r focal
: Ubuntu version (change to your preferred version)-a amd64
: Architecture
Managing LXC Images
List Available LXC Images on Local:
- images stored locally
- if using traditional LXC
List Remote Images from the LXC Repository:
Show detailed information about an image
Replace the image name/fingerprint, example: abcd1234
Remove an LXC Image
Remove All Unused Images
Manually Delete an Image (If Needed)
or
- Refresh LXC Images:
Managing LXC Containers
List Available Containers
Start a Container
(-d
runs it in the background)
Stop a Running Container
Restart a Container
Destroy (Delete) a Container
Interacting with Containers
Attach to a Running Container
Run a Command Inside a Container
Check Container Status
Show Container Logs
Networking and IP Address Management
List Container IP Addresses
Manually Assign an IP Address
Edit the Container’s Configuration File
Add the Following Network Configuration
Replace ip(192.168.1.100) & gateway(192.168.1.1)
Enable NAT (Network Address Translation)
Forward a Port to a Container
Replace destination port(8080), host port(80) & internal ip(10.0.3.20)
- (This forwards traffic from
8080
on the host to port80
in the container).