On Ubuntu, how does one use Docker to manage Linux containers?

Source: Internet
Author: User
Although standard hardware virtualization technologies (such as KVM, Xen, or Hyper-V) are good at running fully isolated instances of multiple operating systems on a physical host, however, this virtualization technology has various overhead in terms of performance, resource and resource configuration time. Standard machine virtualization labels: UbuntuDocker although standard hardware virtualization technologies (such as KVM, Xen, or Hyper-V) it is good at running fully isolated instances of multiple operating systems on a physical host. However, this virtualization technology has various overhead in terms of performance, resource and resource configuration time. Standard machine virtualization may not be necessary, depending on your actual use cases.

Another lightweight virtualization method is the so-called Linux container (LXC), which provides virtualization at the operating system level. Because there is no overhead for running virtual machines, LXC allows users to run multiple instances of the standard Linux operating system in the lightweight container sandbox. If you build a replicable development/testing environment, or deploy applications in the security sandbox, the container will be very useful.

Docker is an open-source tool developed to facilitate the deployment of Linux containers. Docker is rapidly becoming a de facto standard in container technology and has been adopted by major Linux distributions such as Ubuntu and red hat.

In this tutorial, I will demonstrate how to use Docker to manage Linux containers on Ubuntu 14.04. Note: for earlier versions of Ubuntu, the procedure may be slightly different.

Currently, Docker packages available on Ubuntu only support 64-bit systems. To run it on a 32-bit machine, you need to use the source code to build a 32-bit version of Docker (see here for details ).

Install Docker

With the apt-get command, installing Docker is easy.

 
 
  1. ___FCKpd___0nbsp;sudo apt-get install docker.io 

To allow non-root users to run Docker, add yourself to the docker group. The following command allows the current user to run Docker without the root user permission.

 
 
  1. ___FCKpd___1nbsp;sudo usermod -a -G docker $USER 

Log out and log on again to activate the changes of group members.

Next, edit the Docker configuration file to update the location of the Docker binary code.

 
 
  1. ___FCKpd___2nbsp;sudo vi /etc/default/docker.io 
  2. DOCKER="/usr/bin/docker.io" 

Restart the Docker service.

 
 
  1. ___FCKpd___3nbsp;sudo service docker.io restart 

Manage Docker containers

If you want to start a new Docker container in the Ubuntu operating system, you must first obtain the Ubuntu Docker image file. The following command downloads the Docker image file over the network.

 
 
  1. ___FCKpd___4nbsp;docker pull ubuntu 

You can enable Ubuntu Docker in an interactive mode, as shown below. The last parameter "/bin/bash" is the command that will be executed in the container once started. here is a simple bash shell command.

 
 
  1. ___FCKpd___5nbsp;docker run -i -t ubuntu /bin/bash 

The above Command will immediately start a Ubuntu container (this is the charm of the container !), And provide you with a shell prompt in the container. At this time, you should be able to access the standard Ubuntu operating system in the sandbox environment.

To exit the Docker container, enter "exit" at the prompt in the container ".

You can start different types of containers. For example, to start the Fedora container, run the following command:

 
 
  1. ___FCKpd___6nbsp;docker.io run -i -t fedora /bin/bash 

If the Fedora Docker image file does not exist locally, the command automatically downloads the image file and starts Docker.

You can also do this if you want to start a container that uses a release version. For example, to start Ubuntu 13.04 Docker, run the following command:

 
 
  1. ___FCKpd___7nbsp;docker.io run -i -t ubuntu:13.04 /bin/bash 

Container Network

Docker uses the Linux Bridge to interconnect containers and connect them to external networks. After Docker is installed, you will see the automatically formed docker0 Linux Bridge by default. Each container you create is connected to the docker0 bridge interface.

Custom Linux Bridge

You can also use a custom Linux Bridge to interconnect containers. To do this, you can create a custom Bridge and configure it, as shown below. You can assign a separate subnet to the bridge and assign an IP address to Docker from the subnet. I will use 10.0.0.0/24 as the Docker subnet.

 
 
  1. ___FCKpd___8nbsp;sudo apt-get install bridge-utils 
  2. ___FCKpd___8nbsp;sudo brctl addbr br0 
  3. ___FCKpd___8nbsp;sudo ifconfig br0 10.0.0.1 netmask 255.255.255.0 

To enable Docker to use a custom Bridge, add "-B = br0" to the DOCKER_OPTS variable in/etc/default/docker. io, and then restart the Docker service.

 
 
  1. ___FCKpd___9nbsp;sudo service docker.io restart 

Now, any new container is connected to br0, and its IP address is automatically allocated from 10.0.0.0/24.

Other customization

You can also customize Docker's default network settings by modifying the DOCKER_OPTS variable in/etc/default/docker. io.

  • -Dns 8.8.8.8-dns 8.8.4.4: specifies the DNS server used by the container.
  • -Icc = false: isolates containers from each other.

Troubleshooting

1. when you run the docker. io Command, you will encounter the following error.

 
 
  1. Dial unix/var/run/docker. sock: no such file or directory (there is no such file or directory)

This error may occur because the Docker daemon is not running. Check the Docker daemon status and make sure to start it first.

 
 
  1. ___FCKpd___11nbsp;sudo service docker.io status 
  2. ___FCKpd___11nbsp;sudo service docker.io start 

Link: http://xmodulo.com/2014/05/manage-linux-containers-docker-ubuntu.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.