Difference between revisions of "CentOS 7.x create lxc container"
From Notes_Wiki
(Created page with "<yambe:breadcrumb>CentOS_7.x_lxc|CentOS 7.x lxc</yambe:breadcrumb> =CentOS 7.x create lxc container= ==Create CentOS container== To create CentOS lxc containers use follo...") |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x virtualization|Virtualization]] > [[CentOS 7.x lxc|Lxc]] > [[CentOS 7.x create lxc container]] | |||
==Create CentOS container== | ==Create CentOS container== | ||
Line 9: | Line 8: | ||
#:: ls /usr/share/lxc/templates/ | #:: ls /usr/share/lxc/templates/ | ||
#:</pre> | #:</pre> | ||
# Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at [[CentOS 7.x lxc container creation fails due to host resolution]] | |||
# Create container using: | # Create container using: | ||
#:<pre> | #:<pre> | ||
Line 76: | Line 76: | ||
==Create debian container== | ==Create debian container== | ||
To create debian container use: | To create debian container use: | ||
# Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at [[CentOS 7.x lxc container creation fails due to host resolution]] | |||
# Create lxc container | # Create lxc container | ||
#:<pre> | #:<pre> | ||
Line 112: | Line 113: | ||
#:: DEF_HTTPS_MIRROR=”https://mirrors.kernel.org/ubuntu” | #:: DEF_HTTPS_MIRROR=”https://mirrors.kernel.org/ubuntu” | ||
#:</pre> | #:</pre> | ||
# Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at [[CentOS 7.x lxc container creation fails due to host resolution]] | |||
# Create ubuntu container using: | # Create ubuntu container using: | ||
#:<pre> | #:<pre> | ||
Line 141: | Line 143: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x virtualization|Virtualization]] > [[CentOS 7.x lxc|Lxc]] > [[CentOS 7.x create lxc container]] |
Latest revision as of 09:02, 25 August 2022
Home > CentOS > CentOS 7.x > Virtualization > Lxc > CentOS 7.x create lxc container
Create CentOS container
To create CentOS lxc containers use following steps:
- Checking existing container templates using:
- ls /usr/share/lxc/templates/
- Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at CentOS 7.x lxc container creation fails due to host resolution
- Create container using:
- lxc-create -n centos_lxc -t centos
- where, centos_lxc is the container name and centos is name of template.
- If this is first container with chosen template then the command might download the packages first. These packages are cached in '/var/cache/lxc' for future use to avoid re-download. The container itself gets created in '/var/lib/lxc'
- Check container root password using:
- cat /var/lib/lxc/centos_lxc/tmp_root_pass
- Note that you would be forced to change root password on first login.
- Optionally reset container root password using:
- chroot /var/lib/lxc/centos_lxc/rootfs passwd
- Check existing containers using:
- lxc-ls
- Check running containers using:
- lxc-ls --active
- Start container in background using:
- lxc-start -n lxc_centos -d
- Do not try to start it in foreground as it would hang and you would have to kill it after password reset using:
- lxc-stop -n lxc_centos -k
- Attach console to container using:
- lxc-console -n lxc_centos -t 0
- Disconnect from this console using Ctrl^a+q
- To get information on container use:
- lxc-info -n centos_lxc
- To stop container use:
- lxc-stop -n lxc_centos
- Note that this takes long time
- Note that containers can be created using release and architecture values as:
- lxc-create -n mycentos6 -t download -- -d centos -r 6 -a i386
- For centos6 root password file is not created. Hence reset root password using:
- chroot /var/lib/lxc/mycentos6/rootfs
- before using container
- Containers can be cloned using:
- lxc-clone mycentos6 mycentos6-2
- Note that this requires container to be stopped first.
- Containers can be destroyed using
- lxc-destroy -n mycentos6
Create debian container
To create debian container use:
- Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at CentOS 7.x lxc container creation fails due to host resolution
- Create lxc container
- lxc-create -n mydeb -t debian
- Note that this requires debootstrap package. The first download may take considerable time to build local package cache. If download fails then container creation might fail. In such cases simply run the above command again.
- Start container using:
- lxc-start -n mydeb -d
- Attach console using:
- lxc-console -n mydeb -t 0
- Login using root:root
- Detach from container using 'Ctrl^a'+q. Or shutdown container using:
- shutdown -h now
- and after shutdown console will detach automatically.
Create ubuntu container
To create ubuntu container use:
- First ensure following packages are installed:
- yum -y install debootstrap perl
- Create necessary symbolic links
- cd /usr/sbin; ln -sf debootstrap qemu-debootstrap
- Configure qemu-debootstrap by editing '/usr/sbin/qemu-debootstrap' and replacing following lines:
- DEF_MIRROR=”http://mirrors.kernel.org/ubuntu”
- DEF_HTTPS_MIRROR=”https://mirrors.kernel.org/ubuntu”
- Optionally change DNS to 4.2.2.2, 8.8.8.8 that work everywhere to avoid issue mentioned at CentOS 7.x lxc container creation fails due to host resolution
- Create ubuntu container using:
- lxc-create -n myubuntu -t ubuntu
-
- The first download may take time to build package cache. If download fails try above command again.
- To create container using release and architecture values use:
- lxc-create -n container_name -t container_template -- -r distro_release -a distro_architercture
- For example:
- lxc-create -n mywheezy -t debian -- -r wheezy -a amd64
- Start container using:
- lxc-start -n myubuntu -d
- Connect to console using:
- lxc-console -n myubuntu -t 0
- Login using ubuntu:ubuntu. You can access root prompt using:
- sudo su -
- Exit from container using Ctrl^a+q
Home > CentOS > CentOS 7.x > Virtualization > Lxc > CentOS 7.x create lxc container