SlideShare a Scribd company logo
Linux Containers
LXC
Open Source Camp Moldova 2018
$ whoami
Vladimir Melnic
Developer
DevOps
https://github.com/vmelnic
https://fb.com/melnic.vladimir
2
$ man lxc
LXC (Linux Containers) is an operating-system-level virtualization method for
running multiple isolated Linux systems (containers) on a control host using a
single Linux kernel. https://en.wikipedia.org/wiki/LXC
LGPL-2.1
C 88.9% Shell 7.4% M4 2.5% Other 1.2%
Initial release: August 6, 2008
Stable release: 3.0.0, 28 May 2018
3
$ man lxd
LXD is a next generation system container manager. It offers an user experience
similar to virtual machines but using Linux containers instead.
https://linuxcontainers.org/lxd/introduction/
Apache-2.0
Go 91.0%, Shell 7.9%, Other 1.1%
Stable release: 3.0.0, 3 Apr 2018
4
Features
● cgroups - CPU, memory, block I/O, network, etc.
● namespaces - Process IDs, hostnames, user IDs, file names etc.
● unprivileged containers
● snapshot
● migrations
● LXD - Rest API
● LXCFS - Userspace (FUSE) filesystem
https://linuxcontainers.org/lxcfs/introduction/
5
Install
# Ubuntu:
$ sudo apt install lxd lxd-client
# Centos/RHEL 7:
$ sudo yum install yum-plugin-copr epel-release
$ sudo yum copr enable ngompa/snapcore-el7
$ sudo yum install snapd
$ sudo snap install lxd
https://discuss.linuxcontainers.org/t/lxd-on-centos-7/1250
6
Configure
$ sudo lxd init
> Do you want to configure a new storage pool (yes/no) [default=yes]? yes
> Name of the storage backend to use (dir or zfs) [default=dir]: dir
> Would you like LXD to be available over the network (yes/no) [default=no]? yes
> Address to bind LXD to (not including port) [default=all]: all
> Port to bind LXD to [default=8443]: 8443
> Trust password for new clients: *
> Again: *
> Do you want to configure the LXD bridge (yes/no) [default=yes]? yes
7
Configuring - network 1/11
8
Configuring - network 2/11
9
Configuring - network 3/11
10
Configuring - network 4/11
11
Configuring - network 5/11
12
Configuring - network 6/11
13
Configuring - network 7/11
14
Configuring - network 8/11
15
Configuring - network 9/11
16
Configuring - network 10/11
17
Configuring - network 11/11
18
$ sudo lxd init
> Do you want to configure a new storage pool (yes/no) [default=yes]?yes
> Name of the storage backend to use (dir or zfs) [default=dir]:dir
> Would you like LXD to be available over the network (yes/no) [default=no]?yes
> Address to bind LXD to (not including port) [default=all]:all
> Port to bind LXD to [default=8443]: 8443
> Trust password for new clients: *
> Again: *
> Do you want to configure the LXD bridge (yes/no) [default=yes]?yes
> LXD has been successfully configured.
$
19
Creating and starting
# Creating a container without starting it:
$ sudo lxc init ubuntu:16.04 <container>
# Creating and starting a new container:
$ sudo lxc launch ubuntu:16.04 <container>
https://linuxcontainers.org/lxd/getting-started-cli/
20
21
List containers
$ sudo lxc list
22
23
Start, stop and restart containers
# Start container:
$ sudo lxc start <container>
# Stop container:
$ sudo lxc stop <container>
# Restart container:
$ sudo lxc restart <container>
24
25
Delete containers
$ sudo lxc delete <container>
26
27
Exec
# Get a shell inside container:
$ sudo lxc exec <container> -- /bin/bash
# Run command inside container:
$ sudo lxc exec <container> -- apt-get upgrade -y
28
29
30
Images 1/2
# Built-in image remotes:
● ubuntu: (for stable Ubuntu images)
● ubuntu-daily: (for daily Ubuntu images)
● images: (for a bunch of other distros)
# Start a container from image:
$ sudo lxc launch ubuntu:14.04 my-ubuntu
$ sudo lxc launch ubuntu-daily:16.04 my-ubuntu-dev
$ sudo lxc launch images:centos/6/amd64 my-centos
31
Images 2/2
# Using a remote LXD as an image server:
$ sudo lxc remote add my-images 1.2.3.4
$ sudo lxc launch my-images:image-name your-container
32
List images
# Local images:
$ sudo lxc image list
# Built-in image remotes:
$ sudo lxc image list ubuntu:
$ sudo lxc image list ubuntu-daily:
$ sudo lxc image list images:
https://stgraber.org/2016/03/30/lxd-2-0-image-management-512
33
34
35
Container info
# Getting detailed information from a container:
$ sudo lxc info <container>
36
37
Snapshot management
# Creating a snapshot:
$ sudo lxc snapshot <container> <snapshot>
# Listing snapshots:
$ sudo lxc info <container>
# Restoring a snapshot:
$ sudo lxc restore <container> <snapshot>
# Creating a new container from a snapshot:
$ sudo lxc copy <source container>/<snapshot> <destination container>
# Deleting a snapshot:
$ sudo lxc delete <container>/<snapshot>
38
39
40
Cloning and renaming
# Copying a container:
$ sudo lxc copy <source container> <destination container>
# Moving a container:
$ sudo lxc move <old name> <new name>
41
42
43
Resource control
● Disk (only for ZFS or btrfs storage backend)
● CPU
● Memory
● Network I/O (only supported for “bridged” and “p2p” type interfaces)
● Block I/O
https://stgraber.org/2016/03/26/lxd-2-0-resource-control-412
44
Applying some limits
# Container-wide limits:
$ sudo lxc config set <container> <key> <value>
# Profile:
$ sudo lxc profile set <profile> <key> <value>
# Device-specific:
$ sudo lxc config device set <container> <device> <key> <value>
45
CPU
# Limit a container to 1 CPU:
$ sudo lxc config set c1 limits.cpu 1
46
47
Memory
# Limit a container memory (RAM) to 256 MB:
$ sudo lxc config set c1 limits.memory 256MB
48
49
Questions?
50

More Related Content

PDF
Kubernetes dealing with storage and persistence
PPTX
Kubernetes 101 for Beginners
PDF
Kubernetes Introduction
PDF
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
PDF
Rancher 2.0 Technical Deep Dive
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
PPTX
Github in Action
PDF
Kubernetes - A Comprehensive Overview
Kubernetes dealing with storage and persistence
Kubernetes 101 for Beginners
Kubernetes Introduction
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
Rancher 2.0 Technical Deep Dive
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Github in Action
Kubernetes - A Comprehensive Overview

What's hot (20)

PDF
Kubernetes Basics
PPTX
Kubernetes Introduction
PPTX
쿠버네티스 ( Kubernetes ) 소개 자료
PPTX
Gitlab CI/CD
PDF
PPTX
Introduction to CI/CD
PDF
CI CD Pipeline Using Jenkins | Continuous Integration and Deployment | DevOps...
PDF
Jenkins를 활용한 Openshift CI/CD 구성
PPTX
CI/CD with GitHub Actions
PDF
DevOps with GitHub Actions
PPTX
Everything You Need To Know About Persistent Storage in Kubernetes
PPTX
Kubernetes Introduction
PDF
KubeVirt (Kubernetes and Cloud Native Toronto)
PDF
Free GitOps Workshop + Intro to Kubernetes & GitOps
PPTX
Azure kubernetes service (aks)
ZIP
Continuous Integration, Build Pipelines and Continuous Deployment
PPTX
CI/CD Best Practices for Your DevOps Journey
PDF
Ansible, best practices
PDF
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
PDF
Gitlab, GitOps & ArgoCD
Kubernetes Basics
Kubernetes Introduction
쿠버네티스 ( Kubernetes ) 소개 자료
Gitlab CI/CD
Introduction to CI/CD
CI CD Pipeline Using Jenkins | Continuous Integration and Deployment | DevOps...
Jenkins를 활용한 Openshift CI/CD 구성
CI/CD with GitHub Actions
DevOps with GitHub Actions
Everything You Need To Know About Persistent Storage in Kubernetes
Kubernetes Introduction
KubeVirt (Kubernetes and Cloud Native Toronto)
Free GitOps Workshop + Intro to Kubernetes & GitOps
Azure kubernetes service (aks)
Continuous Integration, Build Pipelines and Continuous Deployment
CI/CD Best Practices for Your DevOps Journey
Ansible, best practices
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Gitlab, GitOps & ArgoCD
Ad

Similar to Linux Containers (LXC) (20)

PPTX
PDF
Docker and friends at Linux Days 2014 in Prague
PDF
Linux Containers & Docker
PDF
SBA Live Academy - Secure Containers for Developer by Mathias Tausig
PDF
Drupalcamp es 2013 drupal with lxc docker and vagrant
PPTX
Lxc – next gen virtualization for cloud intro (cloudexpo)
PDF
Practical Lxc And Lxd Linux Containers For Virtualization And Orchestration S...
PDF
Lightweight Virtualization in Linux
PDF
Linuxcon Barcelon 2012: LXC Best Practices
PDF
Automate drupal deployments with linux containers, docker and vagrant
DOCX
Isolating an applications using LXC – Linux Containers
ODP
Docker - The Linux Container
PDF
Lxc- Introduction
PDF
LXD Container Hypervisor
PPTX
Lecture6_Linux network for students .pptx
PDF
Virtualization which isn't: LXC (Linux Containers)
PDF
Let's Containerize New York with Docker!
PDF
Evolution of containers to kubernetes
PDF
Revolutionizing the cloud with container virtualization
Docker and friends at Linux Days 2014 in Prague
Linux Containers & Docker
SBA Live Academy - Secure Containers for Developer by Mathias Tausig
Drupalcamp es 2013 drupal with lxc docker and vagrant
Lxc – next gen virtualization for cloud intro (cloudexpo)
Practical Lxc And Lxd Linux Containers For Virtualization And Orchestration S...
Lightweight Virtualization in Linux
Linuxcon Barcelon 2012: LXC Best Practices
Automate drupal deployments with linux containers, docker and vagrant
Isolating an applications using LXC – Linux Containers
Docker - The Linux Container
Lxc- Introduction
LXD Container Hypervisor
Lecture6_Linux network for students .pptx
Virtualization which isn't: LXC (Linux Containers)
Let's Containerize New York with Docker!
Evolution of containers to kubernetes
Revolutionizing the cloud with container virtualization
Ad

More from Vladimir Melnic (14)

PDF
Drupal Global Trainig Day Moldova 2018
PDF
PGP - confidențialitate in mediul online
PDF
Drupal Winter Day 2017
PDF
Drupal Winter Day 2017 Workshop
PDF
Drupal Winter Day 2017 Workshop - Personal Blog
PDF
Developer Offline 9 - Futurity
PDF
Ecosistemul Drupal
PDF
Xdebug as a Drupal debugging tool
PDF
Eu code week moldova
PDF
Drupal Install FEST
PDF
PDF
Securitatea sete urilor pe drupal
PDF
Instalare drupal
ODP
New vision in server administration
Drupal Global Trainig Day Moldova 2018
PGP - confidențialitate in mediul online
Drupal Winter Day 2017
Drupal Winter Day 2017 Workshop
Drupal Winter Day 2017 Workshop - Personal Blog
Developer Offline 9 - Futurity
Ecosistemul Drupal
Xdebug as a Drupal debugging tool
Eu code week moldova
Drupal Install FEST
Securitatea sete urilor pe drupal
Instalare drupal
New vision in server administration

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...

Linux Containers (LXC)

  • 3. $ man lxc LXC (Linux Containers) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel. https://en.wikipedia.org/wiki/LXC LGPL-2.1 C 88.9% Shell 7.4% M4 2.5% Other 1.2% Initial release: August 6, 2008 Stable release: 3.0.0, 28 May 2018 3
  • 4. $ man lxd LXD is a next generation system container manager. It offers an user experience similar to virtual machines but using Linux containers instead. https://linuxcontainers.org/lxd/introduction/ Apache-2.0 Go 91.0%, Shell 7.9%, Other 1.1% Stable release: 3.0.0, 3 Apr 2018 4
  • 5. Features ● cgroups - CPU, memory, block I/O, network, etc. ● namespaces - Process IDs, hostnames, user IDs, file names etc. ● unprivileged containers ● snapshot ● migrations ● LXD - Rest API ● LXCFS - Userspace (FUSE) filesystem https://linuxcontainers.org/lxcfs/introduction/ 5
  • 6. Install # Ubuntu: $ sudo apt install lxd lxd-client # Centos/RHEL 7: $ sudo yum install yum-plugin-copr epel-release $ sudo yum copr enable ngompa/snapcore-el7 $ sudo yum install snapd $ sudo snap install lxd https://discuss.linuxcontainers.org/t/lxd-on-centos-7/1250 6
  • 7. Configure $ sudo lxd init > Do you want to configure a new storage pool (yes/no) [default=yes]? yes > Name of the storage backend to use (dir or zfs) [default=dir]: dir > Would you like LXD to be available over the network (yes/no) [default=no]? yes > Address to bind LXD to (not including port) [default=all]: all > Port to bind LXD to [default=8443]: 8443 > Trust password for new clients: * > Again: * > Do you want to configure the LXD bridge (yes/no) [default=yes]? yes 7
  • 19. $ sudo lxd init > Do you want to configure a new storage pool (yes/no) [default=yes]?yes > Name of the storage backend to use (dir or zfs) [default=dir]:dir > Would you like LXD to be available over the network (yes/no) [default=no]?yes > Address to bind LXD to (not including port) [default=all]:all > Port to bind LXD to [default=8443]: 8443 > Trust password for new clients: * > Again: * > Do you want to configure the LXD bridge (yes/no) [default=yes]?yes > LXD has been successfully configured. $ 19
  • 20. Creating and starting # Creating a container without starting it: $ sudo lxc init ubuntu:16.04 <container> # Creating and starting a new container: $ sudo lxc launch ubuntu:16.04 <container> https://linuxcontainers.org/lxd/getting-started-cli/ 20
  • 21. 21
  • 22. List containers $ sudo lxc list 22
  • 23. 23
  • 24. Start, stop and restart containers # Start container: $ sudo lxc start <container> # Stop container: $ sudo lxc stop <container> # Restart container: $ sudo lxc restart <container> 24
  • 25. 25
  • 26. Delete containers $ sudo lxc delete <container> 26
  • 27. 27
  • 28. Exec # Get a shell inside container: $ sudo lxc exec <container> -- /bin/bash # Run command inside container: $ sudo lxc exec <container> -- apt-get upgrade -y 28
  • 29. 29
  • 30. 30
  • 31. Images 1/2 # Built-in image remotes: ● ubuntu: (for stable Ubuntu images) ● ubuntu-daily: (for daily Ubuntu images) ● images: (for a bunch of other distros) # Start a container from image: $ sudo lxc launch ubuntu:14.04 my-ubuntu $ sudo lxc launch ubuntu-daily:16.04 my-ubuntu-dev $ sudo lxc launch images:centos/6/amd64 my-centos 31
  • 32. Images 2/2 # Using a remote LXD as an image server: $ sudo lxc remote add my-images 1.2.3.4 $ sudo lxc launch my-images:image-name your-container 32
  • 33. List images # Local images: $ sudo lxc image list # Built-in image remotes: $ sudo lxc image list ubuntu: $ sudo lxc image list ubuntu-daily: $ sudo lxc image list images: https://stgraber.org/2016/03/30/lxd-2-0-image-management-512 33
  • 34. 34
  • 35. 35
  • 36. Container info # Getting detailed information from a container: $ sudo lxc info <container> 36
  • 37. 37
  • 38. Snapshot management # Creating a snapshot: $ sudo lxc snapshot <container> <snapshot> # Listing snapshots: $ sudo lxc info <container> # Restoring a snapshot: $ sudo lxc restore <container> <snapshot> # Creating a new container from a snapshot: $ sudo lxc copy <source container>/<snapshot> <destination container> # Deleting a snapshot: $ sudo lxc delete <container>/<snapshot> 38
  • 39. 39
  • 40. 40
  • 41. Cloning and renaming # Copying a container: $ sudo lxc copy <source container> <destination container> # Moving a container: $ sudo lxc move <old name> <new name> 41
  • 42. 42
  • 43. 43
  • 44. Resource control ● Disk (only for ZFS or btrfs storage backend) ● CPU ● Memory ● Network I/O (only supported for “bridged” and “p2p” type interfaces) ● Block I/O https://stgraber.org/2016/03/26/lxd-2-0-resource-control-412 44
  • 45. Applying some limits # Container-wide limits: $ sudo lxc config set <container> <key> <value> # Profile: $ sudo lxc profile set <profile> <key> <value> # Device-specific: $ sudo lxc config device set <container> <device> <key> <value> 45
  • 46. CPU # Limit a container to 1 CPU: $ sudo lxc config set c1 limits.cpu 1 46
  • 47. 47
  • 48. Memory # Limit a container memory (RAM) to 256 MB: $ sudo lxc config set c1 limits.memory 256MB 48
  • 49. 49