Docker Quick Start and environmental configuration _docker

Source: Internet
Author: User
Tags curl port number docker ps docker cp docker hub docker run docker machine

Objective

Data Science development environment configuration is a headache, will encounter the package version inconsistency, the wrong information is not familiar with the compilation time and so on. It's easy to be crestfallen and makes this first step in data science very difficult. And it's a completely uncommon entry threshold.

Fortunately, over the past few years there have been technologies that have been able to solve this problem by building an isolated environment. The technology we're going to introduce in this article is called Docker. Docker enables developers to build a data science development environment simply and quickly, and supports data exploration using tools such as Jupyter notebooks.

Brief introduction

Docker initially dotcloud an amateur project within the company

Docker is based on the Go language

The goal of the Docker project is to implement lightweight operating system virtualization solutions

Docker is based on technologies such as Linux containers (LXC)

The launch of the Docker container can be implemented at the second level, which is much faster than the traditional virtual machine approach

Docker is highly utilized for system resources and can run thousands of Docker containers on a single host

The following picture compares the differences between Docker and traditional virtualization, and the visible container is virtualized at the operating system level, directly reusing the local host's operating system, while the traditional approach is implemented at the hardware level.

In addition to running the application, the container basically does not consume additional system resources, so the performance of the application is very high, and the overhead of the system is as small as possible. Traditional virtual machines run 10 different applications with 10 virtual machines, and Docker only needs to start 10 isolated applications.

The main advantages are:

Faster delivery and deployment-the container becomes the smallest unit

More efficient virtualization-kernel-level virtualization

Easier migration and expansion

Simpler management

Basic concepts

The main three:

Mirroring (image)

A read-only template that mirrors can be used to create Docker containers

You can simply create or update an existing mirror, or download it directly using someone else's

Container (Container)

A container is a running instance created from a mirror, creating a layer of writable layers at startup as the topmost (because mirroring is read-only)

Can be started, started, stopped, deleted. Each container is a secure platform that is isolated from each other

You can think of a container as a simplified version of the Linux environment (including root user rights, process space, user space, and network space, etc.) and the applications running in it

Warehouse (Repository)

Places to centrally store mirrored files

The largest public warehouse is the Docker Hub.

The public warehouses in China include Docker Pool, etc.

When a user creates his or her own mirror, it can be uploaded to a public or private warehouse using the push command, so that the next time you use the mirror on another machine, you just need to pull down from the warehouse.

The concept of Docker warehouses is similar to Git, which can be understood as a hosting service such as GitHub

Installation

The official web site offers a version of the Mac, Linux, and Windows installation tutorials. Because I intend to use the virtual machine to install the test, so this is mainly to take the installation of Linux tutorial, but the other should be similar. My Ubuntu version is 14.04 LTS, trusty.

Docker currently can only be installed on 64-bit platforms, and requires a kernel version of not less than 3.10, in fact, the new kernel is better, the low kernel version of the easy to create functional instability. You can check the kernel version by using the following command (two-way):

parallels@ubuntu:~$ uname-a
Linux ubuntu 3.13.0-83-generic #127-ubuntu SMP Fri Mar 00:25:37 UTC 2016 x86_64 x86_64 x86_64 Gnu/linux
parallels@ubuntu:~$ cat/proc/version
Linux version 3.13.0-83-generic (buildd@lgw01-55) (gcc version 4.8.2 (ubuntu 4.8.2-19UBUNTU1) #127-ubuntu SMP Fri Mar 00:25:37 UTC 2016

Here we follow the official website of the tutorial, do not use apt-get but curl to use to install.

1, if not installed curl, use sudo apt-get update; sudo apt-get install cur l for installation

2, download the latest Docker packagecurl -fsSL https://get.docker.com/ | sh

If you want to non-root use the user's role, use sudo usermod -aG docker parallels (here parallels is the username), note that you need to log off and log back in to apply the changes

3, verify the installation

Needs to be enabled firstdocker sudo service docker start

Then you can use it docker version to view the version

Last used docker run hello-world to test

Version information

parallels@ubuntu:~$ Docker version
Client:
 version:  1.10.3
 API version:1.22 go
 version:go1.5.3
 Git COMMIT:20F81DD
 Built:  Thu 15:54:52 2016
 os/arch:  linux/amd64

Server:
 Version:  1.10.3
 API version:1.22 go
 version:go1.5.3
 Git commit:20f81dd
 Built:  Thu Mar 15:54:52
 2016 Arch:  linux/amd64

The results of the successful running of Hello World

parallels@ubuntu:~$ Docker run Hello-world

Hello from Docker.
This message shows the your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "Hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from this image which runs the
 executable that produces the output for you AR e currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it to
 your terminal.

To try something more ambitious, you can run a Ubuntu container with:
 $ docker run-it Ubuntu Bash

Share images , automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and idea

S, visit:
 https://docs.docker.com/userguide/

The following are part of the curriculum requirements.

We need to install docker machine and virtual box , the specific steps are:

# get permission
$ sudo su
# download docker Machine binary file 
$ curl-l https://github.com/docker/machine/releases/download/v0 .6.0/docker-machine-' uname-s '-' uname-m ' >/usr/local/bin/docker-machine && chmod +x/usr/local/bin/ Docker-machine
# Verify installation
$ docker-machine version
Docker-machine version 0.6.0, build e27fb87

Add source

Add this line to the /etc/apt/sources.list filedeb http://download.virtualbox.org/virtualbox/debian trusty contrib

wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Update and installsudo apt-get update; sudo apt-get install virtualbox-5.0

Configuration

Then there are some configurations that reset the default virtual machine first

Delete the original default (if any)docker-machine rm default

Create a new default virtual machine docker-machine create --driver virtualbox default (This step may need to wait, I am using Parallel Desktop 11, I also need to open CPU virtualization in the virtual machine settings, mainly support Vt-x)

Then if you choose Virtual Box directly in the menu, you will find nothing, the trick is to enter VirtualBox in the command line just now, then you can see the following interface:

Select Port forwarding in Settings-network, and then add the records as shown

Here the Host port:9234 is recorded as A,guest port:9001 as B. You can then start the mirror provided by the teacher in Docker:

Command for docker run -it -p 9001:9000 cmusvsc/apachecmda:1.1 (need to download a period of time, and then extract a period of time), here 9001 is recorded as D c,9000.

It then connects directly to the virtual machine in the Docker, and you can see from the following figure that the contents of the front of the command line also change. Then we enter the command to open the front

Cd/home/spring2016/apachecmda-frontend
/activator Run # is equivalent to opening on port 9000.

Do not close the current terminal, open a new terminal. Use

Docker exec-it ' Docker ps-q '/bin/bash

Enter the Docker being executed

After waiting for a while, continue to walk the following command

# Open MySQL server
service mysql start
cd/home/spring2016/apachecmda-backend
/activator "Run 9034"

And then you can see

Then wait a while (the first run needs to be compiled) to see the main page:

You can also try to directlylocalhost:9001

Do you remember the front port forwarding? Here's an explanation:

A, which is 9234, is the port number that the user accesses

B, which is 9001, we forwarded the port via the virtual machine from 9234 to 9001.

C, which is 9001 (Docker run-it-p 9001:9000 cmusvsc/apachecmda:1.1 in this command), is the port that the virtual machine continues to forward

D, which is 9000 (the Docker run-it-p 9001:9000 cmusvsc/apachecmda:1.1 in this command), is the port in the Docker container that receives the request.

In other words, B and C must be the same, and A and D can be set in the command. As for why the backend needs to run on port 9034, it is because the front-end and the backend communicate through this port (which should be written dead in the code)

Mount the host data volume inside the container, and you can do folder mapping by using the following command

Docker run-it-p 9999:9999-p 9001:9000-v ~/localfolder:/sharedfolder cmusvsc/apachecmda:1.1

Copy files from the container to the host

# list Container
docker PS
# Copy This I don't know why not
Docker CP <containerid>:/file/path/within/container/host/ Path/target
# Mount map
Docker run-it-v/home/parallels/documents/code:/home/code cmusvsc/apachecmda:1.1
# Copy
cp-r spring2016/*./code/

Summarize

The above is the entire content of this article, I hope the content of this article can help, if you have questions you can message exchange.

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.