About linux containers
Linux containers(lxc) are lightweight operating system level virtualization technology. Unlike some hardware level virtualization solutions(virtual machines), no hardware emulation is used in containers. All all the containers shares the kernel as well as the resources such as CPU, RAM, Hard disk, and network etc of the original host machine.
Following are the basic/main commands to install and manage linux containers(lxc)
View container info
Connect to container
SSH to container
Install mongodb via lxc
In order to install mongodb via lxc, first we have to create lxc container then needs to connect to it(via ssh or lxc-console) and install the mongodb. After installing mongodb inside the container, we can connect to it from host machine via container ip and mongodb port.
Create and connect to container
Install mongodb inside the container
After installing we can connect to mongodb from(with in) inside the container via default host(localhost) and default port(27017)
Allow to connect mongodb from outside the container
By default mongodb allow to connect via localhost. It restricted via mongodb config file’s(in /etc/mongodb.conf) bindIp field(Bind IP is a MongoDB option that restricts connections to specifics IPs)
In order to connect mongodb(installed in the mongodb container) from other hosts(for an example from another container or from host machine) we have to set the bindIp field to mongodb container ip.
After setting the bindIp, needs to restart the mongodb service
Connect mongodb from host machine
In order to connects to mongodb from host machine, host machine needs to have install the mongodb shell.
Now we can connects to mongodb installed in mongodb container from the host machine.
On ubuntu by default each container has a directory in
Containers configurations and root file system(rootfs) stored in this directory
Container configurations stored in the config in
Containers root file system stored in