Ubuntu 14.04 (64-bit) install and use Docker

Source: Internet
Author: User
Tags unique id docker ps docker run

Docker Introduction:

Docker is an open-source application container engine that can install a standalone system (similar to a virtual machine (Vmware)) with Docker, but it is very lightweight, and the installed application starts very fast (typically starting within one second); We can put a docker on a computer and start a lot of servers with Docker to simulate the effects of multiple servers on a single computer.

Docker is UNIX-based and can run natively on Linux systems, and in Windows and Macs it works by installing a VirtualBox on your computer during the installation of Docker. Then install a Linux virtual machine in VirtualBox, and Docker is running on this Linux virtual machine. The above process (installation of VirtualBox and Linux virtual machines) is done automatically during the installation of Docker.

Basic concepts:

image : Adocker image is a program that is not running on your computer's hard drive and is a read-only template, for example: An image can contain a complete Ubuntu, or it can include other programs;

container : A container can be said to be a runtime mirror, which is a running instance of a mirror. Each image can be run multiple times at the same time, so there will be multiple containers. These containers run independently of each other.

Since the mirror is read-only, the container starts with a layer of writable layers as the topmost layer, so that it can be arbitrarily altered in the container, but all the changes are in memory and not saved to the hard disk, so there is no change to the image because the mirror is read-only. When the container is closed and deleted, all the work done in the container disappears.

The relationship between a container and a mirror is like a relationship between a class and an object in C + +, or a software on a hard disk and a program that the software is loaded into memory to run.

Warehouse: warehouses are places where image files are centrally stored, similar to Git, and are divided into public warehouses and private warehouses. The public repository is placed on the network to provide images for everyone to download; a private warehouse is a warehouse created locally by the user, and when the user creates a mirror on a computer, it can be uploaded to the private repository and the image can be accessed on another computer next time.

The main discussion here is how to install and use Docker in Ubuntu 14.04 (64-bit), without much discussion.

For more information about Docker:

Docker official website: https://www.docker.com/

Installation tutorial for the Docker website: https://docs.docker.com/

Docker starter Books (highly recommended):

Http://dockerpool.com/static/books/docker_practice/index.html


Ubuntu 14.04 Installation Docker:

The reason for using Ubuntu 14.04 here is because its official website is recommended for the ubuntu14.04 version, and 64 bits (not 32-bit).

First, run the command at the command line:

sudo apt-get update

Then install wget (Ignore this step if your system is already wget):

sudo apt-get install wget

Then use wget to install Docker:

wget-qo-https://get.docker.com/| Sh

After installation, start Docker:

Service Docker start  

Or, use the following command to start Docker:

sudo docker–d

There may be some problems here, please see the FAQ at the end of this article for a specific workaround.

Startup Dcoker can run its own Hello-world program:

sudo docker run  Hello-world

Command explanation:

sudo docker run this command is used to start the image in the format:

sudo docker run [parameters]  image_name [command]

After the run, you can add some parameters to achieve some effect after the container starts, then the image name indicates which image you want to start, and then the image name is a command line command, which is the first command to run automatically after you enter the container; Because sometimes we don't need to go into the container, just start the container, For example: We have created an Ubuntu (image name) of the Apache server image, and now we want to start the server, then simply:

sudo  Docker run  -d–i ubuntu  apachectl Start

Such an Apache server will start;

For example, we just want to print out Ubuntu (image name) in this image in the/etc directory in the Hello.txt content, then we can do so;

sudo  Docker run  -i–t Ubuntu cat/etc/hello.txt

Of course, if you want to go into the image of Ubuntu and then do some command-line operations inside, you can use the following command:

sudo  Docker run-t-I  Ubuntu/bin/bash

(Note:/bin/bash is to enter the command line meaning)

The Run command parameter explains:

-d means that the boot container will run in the background, such as the server we just need it to run silently in the background;

--name (note there are two-), which indicates that the boot container is named ... ;

sudo docker Run–i–t–-name=hello Ubuntu/bin/bash

-T means to start the container in the form of a command-line terminal

-V is used to pass in the container to the file (seemingly unable to pass the folder, you can compress the folder and then pass), the local file path and the path you want to upload to the container separated by colons (all with absolute path), is in the boot container simultaneous:

sudo docker run–i–t–v/home/liujan/hello.txt:/etc/world.txt Ubuntu/bin/bash

means to upload the hello.txt to the container/etc directory and rename it to World.txt, notice that the last file name is written in the container path, such as the world.txt here.

-P (lowercase) is followed by the port number of the machine, followed by a colon, followed by the container port number (PORT1:PORT2), which means that the native port Port1 is mapped to the port Port2 of the container, so that when you access the port Port1 of the native, you are actually accessing the PORT2 port of the container. For example, MySQL default listener port is 3306, so that we can map a port number of this machine to the container's 3306 port, you can access the container's MySQL database (if you container installed MySQL) (by the way, Apache listening port number is 80), Like what:

sudo  docker run–i–t–p 8088:3306  ubuntu  /bin/bash

You can also map multiple native ports and multiple container ports at once:

sudo  docker run–i–t–p 8088:3306-  p 8089:80  ubuntu/bin/bash

Or you can use the command to specify a port that only one IP can access to this container:

sudo docker run–i–t–p 127.0.0.1:8088:3306 Ubuntu/bin/bash

This will only 127.0.0.1 the IP to access the MySQL database in the container.

The-p (uppercase) lowercase P is used to specify the port mappings between the native and the container, but sometimes we don't care about which two ports are mapped, just know that they have port mappings between them. When uppercase P is used, the system automatically maps between the native and the container by selecting two ports:


sudo docker run–i–t–p Ubuntu/bin/bash

To get the image:

We can download the desired image from the Docker website and pull with command:

sudo docker pull  ubuntu

The default is downloaded from the official website

You can also specify the version number of Ubuntu to download:

sudo docker pull ubuntu:12.04

Because sometimes the official website download speed is relatively slow, we can download from other websites:

sudo  Docker pull  Dl.dockerpool.com:5000/ubuntu

Here is downloaded from the Dockerpool, the speed should be faster.

You can also search for the relevant image using the searches command, and then decide which one to download:

sudo  docker search  Ubuntu

Performing the above command will return a list of images associated with Ubuntu.

After downloading the image, you can use the command to view the image that has been downloaded to the Local:

sudo  docker images

If you want to delete a mirror, you can use the following command:

sudo  Docker RMI image name

Such as:

sudo  Docker rmi Ubuntu  #删除ubuntu镜像

or remove all mirrors:

sudo docker rmi $ (sudo docker images-q)

Note: Please exit all containers with this image before deleting the image.

Exporting and loading mirrors

At some point, we have a mirror on a computer, but we want to run the image on another computer, we can export this image from the computer, then copy it to another computer, then load the image:

To export a mirror:

sudo  dcoker–o  export filename  image name sudo  docker–o ubuntu.tar   Ubuntu

Load Image:

sudo docker load--input  image filename sudo  docker load  --input  Ubuntu.tar

To create a mirror using a container:

As mentioned earlier, the mirror is read-only and all operations in the container are not saved to the mirror. In other words, when the container is closed, all of the work we do in the container will be lost. To solve this problem, we can save a container as a mirror, so that the work we do in this container is saved in a new image, and the next time we start the new image directly, we can:

sudo docker commit container ID  new image name Sudo  Docker commit  0b2616b0e5a8  UBUNTU2

In this way, UBUNTU2 contains the work done by the mirrored 0b2616b0e5a8.

When the image is started, it is a container.

Note that before you save the container as a new image, quit the container (rest assured, after exiting the container, the container will still exist in memory, so don't be afraid to lose the job, as long as you do not delete the container on the line)

To view the containers that are running:

sudo  Docker PS

To view all containers that have not been deleted (including stopped):

sudo  Docker ps–a

As you look at the container, you can see that each container has a unique ID (container_id), which we can use to remove a container:

sudo docker RM container ID

Delete all containers:

sudo docker rm $ (sudo dockerps-a)


Problems:

1. When running the container, Mountpoint for the CPU not found error is always reported:

Workaround:

At the command line, enter:

sudo wget-o/etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf

(If not, remove the parameter O)

And then restart the computer.


2. The following error occurred:



Workaround:

To run the command:

sudo docker-d
(Do not close this terminal window)

In the next blog post, we'll discuss how to use Docker to build an Apache server and access the servers in Docker from an external computer.




Ubuntu 14.04 (64-bit) install and use Docker

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.