Use Docker to manage Linux iner containers in Ubuntu
Currently, Full Hardware virtualization technology (KVM, Xen, Hyper-V, etc.) can run multiple independent operating systems on a physical host, but this also brings about some problems: poor performance, waste of resources, and slow system response. Sometimes, Full Hardware virtualization is not the best choice for users.
One alternative is to use lightweight virtualization technology, the so-called LinuX iner Container (LXC), which provides system-level virtualization. Compared with running virtual machines, LXC can run multiple Linux operating systems in a lightweight sandbox container. LXC is useful when you need to set up a development and testing environment that is easy to clone, or want to install applications in a security sandbox.
Docker is an open-source tool that allows users to conveniently deploy Linux iner containers. Docker quickly became an unofficial standard for the iner technology, so it was absorbed by many releases such as Ubuntu and Red Hat.
New virtualization options for the open-source project Docker and Red Hat
Dockerlite: lightweight Linux Virtualization
Detailed explanation of the entire process of building Gitlab CI for Docker
What is the difference between Docker and a normal Virtual Machine?
Docker will change everything
In this tutorial, I will show you how to use Docker to manage LXC in Ubuntu 14.04. Note that some of the content in this tutorial may be slightly different from the operations in other Ubuntu versions.
Currently, only 64-bit Docker installation packages are available in Ubuntu. If you want to run 32-bit Docker, you need to use the source code to compile the 32-bit Docker tool.
Install Docker
Installing Docker with apt-get is a piece of cake.
$ sudo apt-get install docker.io
If you are not a user in the root group, you can add yourself to the docker user group. The following command allows users without root permission to use Docker:
$ sudo usermod -a -G docker $USER
Log On again to make your user group permissions take effect.
The next step is to edit the Docker configuration file and determine the path of the Docker executable file:
$ sudo vi /etc/default/docker.ioDOCKER="/usr/bin/docker.io"
Restart the Docker service:
$ sudo service docker.io restart
Manage Docker Container containers
If you want to create a new Ubuntu operating system under the new Docker container, you first need a Docker image of Ubuntu. The following command downloads a Docker image over the network:
$ docker pull ubuntu
You can use the following command to start the Ubuntu System in Docker. The final parameter "/bin/bash" indicates that once the container is started, a simple bash command is executed first.
$ docker run -i -t ubuntu /bin/bash
The above command will immediately start the Ubuntu container (this is a perfect container !), Then it will provide you with a shell prompt running environment. Now you can access a complete Ubuntu system through this sandbox environment.
Enter the "exit" command to exit the Docker container.
You can also use the following command to access different systems. For example, Fedora:
$ docker.io run -i -t fedora /bin/bash
If the Fedora Docker image does not exist in the system, this command automatically downloads it and starts the Docker container of Fedora.
If you want to enable the System of the specified version, such as Ubuntu 13.04, you can use the following command:
$ docker.io run -i -t ubuntu:13.04 /bin/bash
Container network settings
Docker uses the Linux bridge technology to communicate with other containers and connect to the Internet. After installing Docker, you should see the bridge docker0, which is created by default by Docker. Each container you create is connected to the network through this bridge.
Custom Linux Bridge
To customize a bridge, follow these steps. You can assign a subnet behind the bridge and assign an address to the subnet. The following command assigns the IP address segment 10.0.0.0/24 to the Docker subnet:
$ sudo apt-get install bridge-utils$ sudo brctl addbr br0$ sudo ifconfig br0 10.0.0.1 netmask 255.255.255.0
Then, add the "-B = br0" option in the DOCKER_OPTS variable of the/etc/default/docker. io file and restart the Docker service:
$ sudo service docker.io restart
So far, any created container will be connected to the br0 bridge, and their IP addresses will be automatically allocated from 10.0.0.0/24 ).
Other custom settings
You can set other attributes through the DOCKER_OPTS variable in the/etc/default/docker. io file:
- "-Dns 8.8.8.8-dns 8.8.4.4": specify a DNS server for the container.
- "-Icc = false": isolates the container from other containers.
Troubleshooting
1. When you run the docker. io command, you may encounter the following problems:
dial unix /var/run/docker.sock: no such file or directory
This error may occur because the Docker background process is not started. Check the Docker background process status and make sure it is in the startup status:
- $ Sudo service docker. io status
- $ Sudo service docker. io start
Docker details: click here
Docker: click here
This article permanently updates the link address: