LXC
Commands
forcefully start lxc
lxc-start -n 101 -F
mount lxc virtual disk
pct mount 101
unmount lxc virtual disk
pct unmount 101
repair virtual disk
pct fsck 101
check configuration of lxc
pct config 101
Remove container
pct destroy 101
Restore a container to a new CT 600
pct restore 600 /mnt/backup/vzdump-lxc-777.tar
LXC Containers
-
Create a brand new lxd container:
lxc launch ubuntu:xenial mysql01
-
Create a bash session inside the container:
lxc exec mysql01 bash
-
Install mysql database server within the container:
sudo apt install mysql-server
-
Access the mysql database from inside the container as the root user:
mysql -u root -p
-
Allow remote access to root from any host:
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'password'
where password is the password to be used while accessing mysql from outside of the container.
-
Enable built-in firewall configurer and allow mysql access from outside:
sudo ufw enable && sudo ufw allow mysql
-
Exit the mysql client. Open the file ‘/etc/mysql/mysql.conf.d/mysqld.cnf’ in your favourite text editor and comment the following line out by typing # at the starting of the line:
#bind-address = 127.0.0.1
-
Restart the mysql service:
sudo service mysql restart
-
Now exit the container. We need to check the IP of the container to access the database from the host. ‘lxc list’ should do the trick:
-
Now from your host machine, try accessing the mysql server with the root password that you set in step #5:
mysql -h 10.182.248.44 -u root -p