Docker for Windows installation and linux+php development environment (i)

Source: Internet
Author: User
Tags php development environment ssh account docker ps docker hub docker run oracle vm virtualbox vm virtualbox
What is Docker?

Simply put, Docker is a "container" for programs written by the Go language (Linux containers, LXCS); At present, the cornerstone of cloud services is operating system-level isolation, virtual multiple hosts on the same physical server. Docker implements an application-level isolation; It changes our basic development, Operation unit, by direct Operation Virtual Host (VM), to the "container" that the operation program runs.

Benefits of Docker

Docker benefits: Fast running, agile deployment, flexible, lightweight, open source free.

Boot2docker is a lightweight Linux distribution package designed specifically for Docker to solve the problem of Windows or OS X users not being able to install Docker. The Boot2docker is fully running in memory, 24M in size, and starts only 5-6 seconds. The boot2docker needs to run in VirtualBox.

Steps for installing Docker for Windows

Check system version and hardware virtualization

First, check the Windows operating system version number

The Boot2docker operation requires the operating system to be at least windows 7.1,8/8.1. The measured Windows 7 Ultimate Edition (Windows 7 Ultimate) is also supported.

Second, you need to make sure that your system supports hardware virtualization and is virtualized to Enabled state.

Enabling virtualization support requires several conditions: chipset support, BIOS support, processor support, operating system support.

On the operating system side, the mainstream operating system supports VMM management, so there is no need to consider. Chipsets, which have been supported since the era of Intel 945 (except for netbooks), are not considered. On the CPU side, it can be judged by the Intel official website or by third party inspection software. Therefore, it is more to see if the BIOS is supported.

For Windows 8/8.1 Systems, open Task Manager-Performance tab-CPU to see the status of virtualization turned on. Such as:

If the status is not enabled, it needs to be turned on to the motherboard BIOS.

To enter the BIOS method: When the computer starts up, when the "press DEL to enter SETUP" prompt appears at the bottom of the screen, pressing the "Del" key immediately to enter the BIOS setup program. Some types of bios, you need to open the Boot logo screen press F2 or F10 key to enter, depending on the screen prompts to operate.

For example, find the Intel Virtual technology setting and change disabled to Enabled. Then save the exit to turn on the VT function. Such as:

For Windows 7 systems, you need to install Microsoft's Hardware Virtualization Detection tool (Microsoft? hardware-assisted Virtualization Detection Tool) to determine whether the processor supports virtualization and whether virtualization is turned on. Download and install the HAV detection Tool, the test results follow the onscreen prompts, and then refer to the HAV Detection Tool User Guide for the next steps.

Download Address:

HAV Detection Tool
Http://download.microsoft.com/download/1/9/F/19FD407F-A7E9-4393-A845-D0B1F539678E/havdetectiontool.exe

HAV Detection Tool User Guide
http://download.microsoft.com/download/1/9/F/19FD407F-A7E9-4393-A845-D0B1F539678E/HAV%20Detection%20Tool%20-% 20user%20guide.mht

If a ScreenTip is present, it indicates that the current computer processor supports hardware virtualization and is enabled.

Installing Boot2docker

Next you need to install Boot2docker with some supporting software. Details include:

Docker Client for Windows
Boot2docker management tool and ISO
Oracle VM VirtualBox
Git msys-git UNIX Tools

First click Download Boot2docker for Windows.

Download Address:

Https://s3.amazonaws.com/github-cloud/releases/18047765/825908bc-15b8-11e5-96cb-9a42a043cc39.exe? Response-content-disposition=attachment%3b%20filename%3ddocker-install.exe&response-content-type= application/octet-stream&awsaccesskeyid=akiaistnzfovbijmk3tq&expires=1437386585&signature=wm% 2bttyn4yqc8fhh7waeezw7a5ce%3d

Then double-click the downloaded Docker-install.exe installation file to start the installation. The installation process is best to shut down the computer's related security software prematurely.

The official download speed is relatively slow, can try to the domestic daocloud download http://get.daocloud.io/

Verify that the installation is successful

Start Boot2docker after installation is complete.

After opening the Boot2docker terminal, if the user Account Control prompt appears on the system, select Yes to ensure that the virtual machine VirtualBox complete some computer configuration changes. If you are not prompted, you generally do not need to set.

Note: User Account Control (UAC) is a new security feature for Windows Vista. It prevents malicious software from gaining privileges, even if the user is logged on as an administrator account. To modify UAC in the Control Panel, take the Win7 flagship example: Control Panel → all Control Panel items → user accounts → changing user Account Control settings (change U) Ser account Control setting).

The terminal needs a certain initialization time to start Boot2docker, execute the environment variables required by Docker to run the bash script, and if successful, a $ prompt will appear.

Use the Boot2docker SSH command to enter the VM. You will need to use this command for some basic configuration later.

You can now use the Docker commands directly.

Execute the command on the terminal Docker run Hello-world, enter. If it works, it will output the following:

$ Docker Run hello-worldunable toFind image' Hello-world:latest 'Locallypulling Repository Hello-world theC95931e552:download Complete A8219747be10:download complete status:downloaded newer image forHello-world:latesthello fromDocker.this message shows that your installation appears tobe working correctly. To generate the this message, Docker took theFollowing steps:1.The Docker client contacted theDocker Daemon.2.The Docker daemon pulled the"Hello-world"Image from theDocker Hub. (assumingitWas notAlready locally available.)3.The Docker daemon createdaNewContainer fromThat image which runs theExecutable that produces theOutput you is currently reading.4.The Docker daemon streamed that output to theDocker client, which sentit toYour terminal. ToTrySomething more ambitious, you can run anUbuntu container with: $ docker Run-itUbuntu Bashfor More examples andIdeas, visit:http://docs.docker.com/userguide/

Understanding Containers and mirrors

Take the command Docker run Hello-world as an example:

The container is a simplified version of the Linux operating system, and mirroring is a collection of software that is loaded into a container, and after this command is executed, Docker takes the following actions in sequence:

A. Check if the Hello-world image is installed
B. If not installed, download the image from the Docker Remote warehouse (Docker Hub)
C. Load the image into the container and run it.

Create Doker PHP container, enable PHP development environment

The Docker hub has an image of the individual developer, as well as an official image of the company or organization, you can use the image of the Docker hub, or you can use your own local private mirror (such as local.registry.com:5000/php). Take the building of the PHP development environment as an example and continue to explain how the Docker commands are used.

This is a self-built private image (already integrated with Linux+php+apache), and the private image address is: 172.16.100.71:5000/php

1. Set the host for Windows system, Boot2docker VM

A. Setting up the Windows system Local host

Setting up the Windows system Local host is primarily for easy operation at the cmd command prompt. If you are working in Git bash, you can choose to skip the Windows system Local host settings.

Location: C:\Windows\System32\drivers\etc\hosts

Add a line to the file 172.16.100.71 local.registry.com

B. Set the host for the Boot2docker virtual machine

Enter the virtual machine via the Boot2docker SSH command and execute the command:

sudo vi/etc/hosts
Add a line to the file: 172.16.100.71 local.registry.com
Exit

You can also use the combo command:

"echo $'172.16.100.71 local.registry.com' | sudo tee -a /etc/hosts"

2. Check Settings environment variables

In Git bash, enter:

export

To see if an environment variable has been set automatically: Docker_host,docker_cert_path,docker_tls_verify

Boot2docker Shellinit can display environment variables for Docker clients, so you can set environment variables automatically using the following command

eval"$(boot2docker shellinit)"

If this command cannot be set successfully, you need to add it manually by entering the following command:

export DOCKER_HOST=tcp://192.168.59.103:2376export DOCKER_CERT_PATH=/c/Users/Administrator/.boot2docker/certs/boot2docker-vmexport DOCKER_TLS_VERIFY=1

After execution, enter export to see if the write succeeded.

To enable Windows itself in CMD, you can also manipulate the Docker command by typing the following command in CMD:

set DOCKER_HOST=tcp://192.168.59.103:2376set DOCKER_CERT_PATH=C:/Users/Administrator/.boot2docker/certs/boot2docker-vmset DOCKER_TLS_VERIFY=1

After execution, enter set to see if the write succeeded.

However, the environment variables set by the SET command are temporary and will not work when the CMD command-line window is closed.

The permanent environment variable is set up by: "Computer-Properties-Advanced system Settings-advanced-Environment variables", create a new three system variables and fill in the corresponding values. After Setup is complete, re-open cmd to take effect.

In addition, if you want to run commands such as Boot2docker ssh in cmd, you also need to set up GIT-related environment variables. The method is:

set PATH=%PATH%;"C:\Program Files (x86)\Git\bin"

Permanent environment variable setting method, append the following directory in the System Variable path field (the specific directory is added according to your git installation directory)

; C:\Program Files (x86) \git\bin;

The CMD is then restarted to take effect.

3. Set –insecure-registry option

Starting with Docker 1.3.1, connecting an unsecured private image is not allowed by default. Now we are going to download our own private image, which needs to be set up in the following ways:

boot2docker sshsudo vi /var/lib/boot2docker/profile

Add a row

EXTRA_ARGS="--insecure-registry local.registry.com:5000"

Save and then restart the Docker service:

sudo /etc/init.d/docker restart

You can also merge operations in Git bash:

"echo $'EXTRA_ARGS=\"--insecure-registry local.registry.com:5000\"' | sudo tee -a /var/lib/boot2docker/profile && sudo /etc/init.d/docker restart"

Description: A private mirror address such as local.registry.com:5000 can also be replaced with an IP address.
The tee command parameter-A is appended to the file and is used as appropriate.

The Sudo/etc/init.d/docker Restart command sometimes fails to restart, so we can observe the information of the Docker process with the following command:

|grep docker

If the Docker master process (/usr/local/bin/docker) PID is relatively small and runs for a long time, then no reboot is successful. You need to force the process to kill and then restart.

sudo kill -9 pidsudo /etc/init.d/docker restart

Finally, check the process number and run time with the Ps-ef |grep Docker command to ensure the Docker restarts successfully.

ps -ef |grep dockerexit

4. Download the private image to the local

docker pull local.registry.com:5000/php

Before the image is run, download it locally, if an error occurs, follow the previous steps or error handling to resolve, and then continue with the next steps

5. Check and set the virtual machine shared folder

VirtualBox defaults to host directory C:\Users as a shared folder and is automatically mounted to the virtual machine c/users path. So generally we usually choose to put the data in the host C:\Users directory and then mount it to the container via Docker commands. But as a Windows user, everyone's C disk is often used as system disk, the key data placed on the C disk is more dangerous, once Windows system corruption can not be started may cause data loss.

So, we thought: Can you add the shared folder under other drive characters and mount it to the container?

Of course!!! The steps are a little cumbersome and continue to look down.

Attempts to create shortcuts to other drive-letter shared folders in the C:\Users directory are not feasible.

Here is the correct procedure:

Open the Boot2docker virtual machine GUI, click "Settings"-"shared Folder", and right-click "Add shared Folder" in the "Fixed assignment" menu.

A. Execute boot2docker SSH into the virtual machine, first determine the directory to mount to, if the directory does not exist need to manually create:

boot2docker sshsudo mkdir -p /f/projects/phpdev

B. After creating the directory you want to mount, execute the following command to mount the shared folder.

sudo mount -t vboxsf f/projects/phpdev  /f/projects/phpdev

Or

-t-o uid=1000,gid=50 f/projects/phpdev  /f/projects/phpdev

Such as:

After Mount finishes exiting, Boot2docker ssh re-enters the virtual machine to see if the host shared folder is synced to the Mount directory.

As you can see, the files/folders under the host local directory F:\projects\phpdev have been synchronized to the current virtual machine mount directory, which is under the/f/projects/phpdev path.

Because the Docker container in step six below is the/var/www/html path to mount the/f/projects/phpdev to the container Linux environment, this step is to prepare for the next steps.

In general, in order to ensure data security and integrity, data is not persisted in a container environment created by Docker. The common approach is to map the file system of the local host to the file system of the container environment, which ensures that the data generated in the container environment is stored directly on the user's host disk, without loss of data due to container corruption or failure to persist the container in a timely manner.

According to Boot2docker official (https://github.com/boot2docker/boot2docker) description, Boot2docker has a built-in client enhancement package for Virtual machine folder sharing (VirtualBox Guest additions).

If the following shared folder name exists, the shared folder is automatically mounted to the following location:

Users to Mount to/users
/users Mount to/users
C/users Mount to/c/users
/c/users Mount to/c/users
C:/users Mount to/c/users

If you need to share additional file paths, you need to execute the following command:

-t vboxsf your-other-share-name /some/mount/location

Or

-t-o uid=1000,gid=50 your-other-share-name /some/mount/location

Note: The Linux command ID can view the user's UID (corresponding/etc/passwd) and GID (corresponding to/etc/group)

However, if you restart Windows, these settings will be cleared and will need to be mounted again (of course, a direct restart of BOOT2DOCKER-VM will also erase all configuration data). If you don't want to mount it manually every time, you can add an item to the/etc/fstab

your-other-share-name /some/mount/location vboxsf rw,gid=100,uid=100000

Or

your-other-share-name00

This will automatically mount (the client enhancement Package VirtualBox guest additions needs to be installed).

After performing the manual mount command, the contents of the shared folder are already visible under the/some/mount/location directory.

Since Boot2docker itself is a virtual machine, Docker also acts as a virtual machine environment, and to successfully mount with Docker Run-v Path1:path2, two-step mapping is actually required: Shared folders are first mounted by the host to the Boot2docker virtual machine. It is then mounted to the Docker container environment by the boot2docker virtual machine.

Mount Directory before mounting:

sudo mkdir -p /some/mount/location

Then execute the Mount Mount command above.

To uninstall a shared folder, use the command sudo umount-f/f/projects/phpdev

Attention:

Uninstalling the shared folder requires you to exit the Mount directory before uninstalling, or you will get an error:
Umount:can ' t forcibly umount/f/projects/phpdev:no such file or directory

At the same time should be aware of unloading the directory must be written, note the front of the drive letter F slash/, if the directory to be unloaded is not mounted, will be an error:
Umount:can ' t forcibly umount/f/projects/phpdev:invalid argument

6. Create and run a container based on the image provided

Create and run a container based on a private image that is pulled to the local (linux+apache+php integrated image):

-d-p8000:80-p2222:22---v /f/projects/phpdev:/varlocal.registry.com:5000/php

Where 80 ports are http/nginx default ports and 22 ports are the Linux SSH default ports. The host local directory/f/projects/phpdev is mounted to the container after the next run mode.

Attention:

If you perform a mount failure error on a Windows system git bash, because msysgit will automatically switch directories such as/c/users to c:\Users, you need to use a double slash, and the input command in Git bash is:

-d-p8000:80-p2222:22---v//f//projects//phpdev:/var/www/html local.registry.com:5000/php

Then, with the Docker PS command, you can view the currently running containers.

$ boot2docker.exe ip192.168.59.103

We can ssh into the current PHP container or use SSH tools such as Xshell to connect.

The ssh login command is:

2222 root@192.168.59.103

Note: Boot2docker SSH account password is user/docker, private image is Root/hellonihao

After SSH login, we can see the familiar Linux directory structure.

If no local Phpdev folder will be created automatically, create a new phpinfo.php test file in this directory to output the PHP configuration information.

The Docker host is a boot2docker virtual machine, so it needs to be accessed using the virtual machine's IP to obtain the IP boot2docker IP.

So the above phpinfo.php file access address: 192.168.59.103:8000/phpinfo.php

For example, just build a container based on the CentOS base image and set up a data volume/data command as follows

$dockerrun-it--rm--namecentos--volume=/datalocal.registry.com:5000/centos/bin/bash

Note: In git bash you need to use a double slash to execute

$dockerrun-it--rm--namecentos--volume=//datalocal.registry.com:5000/centos//bin//bash

To mount the host directory to a data volume, the command is as follows:

-it--rm  ---v /c/Users/phpdev:/datalocal.registry.com:5000

Note: You need to use a double slash under Git bash, which is:

$ docker run -it --rm  --name centos -v //c//Users//phpdev:/data local.registry.com:5000/centos //bin//bash 

Other commonly used commands:

Docker rm-f PHP
Docker Ps-l
Docker Images-a
Docker RMI
Docker stop
Docker run
Docker Kill

The above is an introduction to the installation method and Docker use steps for the Docker for Windows version. If there are errors, please feel free to comment, study Docker together.

The next section will share the handling of common errors in the use of Docker installations.

Reference article:

http://docs.docker.com/userguide/"Docker Official Document-User Guide"
Https://github.com/boot2docker/boot2docker "Boot2docker Official Documents"
http://blog.pavelsklenar.com/5-useful-docker-tip-and-tricks-on-windows/

This article from Csdn Blog, reproduced please indicate the source, thank you!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the Docker for Windows installation and linux+php development environment (a), including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.