DockerforWindows installation and Linux + PHP development environment (1)

Source: Internet
Author: User
Tags php development environment docker ps docker hub docker run oracle vm virtualbox vm virtualbox
: This article mainly introduces the installation of DockerforWindows and the establishment of the Linux + PHP development environment (1). If you are interested in the PHP Tutorial, refer to it. What is Docker?

Simply put, Docker is a "container" (Linux containers, LXCs) for running programs written in the GO language. Currently, the foundation of cloud services is the isolation of the operating system level, multiple hosts are virtualized on the same physical server. Docker implements application-level Isolation. it changes the basic development and operation units, and directly operates virtual hosts (VMS ), switch to the "container" where the operating program runs.

Benefits of Docker

Advantages of Docker: fast running, agile deployment, flexibility, lightweight, open source, and free of charge.

Boot2Docker is a lightweight Linux release package designed specifically for Docker. it solves the problem that Windows or OS X users cannot install Docker. Boot2Docker runs completely in the memory, 24 MB in size, and starts in 5-6 seconds. Boot2Docker needs to run in VirtualBox.

How to install and use Docker for Windows

Check System version and hardware virtualization

First, check the Windows OS version number.

The operating system of Boot2Docker must be at least Windows 7.1, 8/8. 1. Windows 7 Ultimate Edition (Windows 7 Ultimate) is also supported.

Second, make sure that your system supports hardware virtualization and virtualization is enabled.

To enable virtualization technology support, you need to support the chipset, BIOS, processor, and operating system.

Mainstream operating systems support VMM management, so you do not need to consider it. In terms of chipset, it has been supported since the Intel 945 (except netbook) era, so you do not need to consider it. In terms of CPU, you can use the Intel official website for queries or third-party detection software for determination. Therefore, it is more important to check whether the BIOS is supported.

For Windows 8/8. 1 system, open the task manager-"Performance" tab-CPU to view the virtualization Enabling status. For example:

If the status is "not enabled", go to the motherboard BIOS to enable it.

How to enter the BIOS: when the computer starts up, when the "Press DEL to enter SETUP" prompt appears at the bottom of the screen, immediately Press the "Del" key to enter the bios setup program. For some types of BIOS, you need to press F2 or F10 on the enable Logo screen. follow the instructions on the screen.

For example, find the Intel Virtual Technology configuration item and change Disabled to Enabled. Save and exit to enable the VT function. For example:

For Windows 7 systems, Microsoft's hardware virtualization detection tool (Microsoft? To determine whether the processor supports Virtualization and whether Virtualization is enabled. Download and install the HAV detection tool. follow the on-screen prompts for the Detection result. then, refer to the HAV detection Tool User Guide for the next step.

:

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 prompt is displayed, it indicates that the current computer processor supports hardware virtualization and is enabled.

Install Boot2Docker

Next, you need to install Boot2Docker and some auxiliary software. Including:

Docker Client for Windows
Boot2Docker management tool and ISO
Oracle VM VirtualBox
Git MSYS-git UNIX tools

First, click download Boot2Docker for Windows.

:

Https://s3.amazonaws.com/github-cloud/releases/18047765/825908bc-15b8-11e5-96cb-9a42a043cc39.exe? Response & response-content-type = application/octet-stream & AWSAccessKeyId = AKIAISTNZFOVBIJMK3TQ & Expires = 1437386585 & Signature = wM % 2bttyn4yqc8fh1_waeezw7a5ce % 3D

Double-click the downloaded docker-install.exe installation file to start installation. It is best to disable computer-related security software in advance during the installation process.

Official download speed is slow, you can try to download the domestic DaoCloud http://get.daocloud.io/

Verify whether the installation is successful

Start Boot2Docker after installation.

After you enable the Boot2Docker terminal, if the system displays the User Account Control prompt, select Yes to ensure that the virtual machine VirtualBox completes some computer configuration changes. If no prompt is displayed, you do not need to set it.

Note: User Account Control (UAC) is a new security function in Windows Vista. It can prevent malware from obtaining privileges, even if users log on as administrator accounts, it can also play a protection role. You can modify the UAC on the Control Panel. for example, the Windows flagship edition is: Control Panel → All Control Panel Items → User Account) → Change User Account Control setting ).

The terminal needs a certain initialization time to start Boot2Docker and execute the required environment variable bash script for running Docker. if the script is started successfully, a $ prompt will appear.

Run the boot2docker ssh command to access the VM. You need to use this command for some basic configurations later.

Now you can directly use the docker command.

Run docker run hello-world on the terminal and press enter. If it runs normally, the following content is output:

$ docker run hello-worldUnable to find image 'hello-world:latest' locallyPulling repository hello-world91c95931e552: Download complete a8219747be10: Download complete Status: Downloaded newer image for hello-world:latestHello from Docker.This message shows that 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 fromthe Docker Hub.    (Assuming it was not already locally available.) 3. The Docker daemon created anew container from that image which runs the    executable that produces the output you are currently reading. 4. The Docker daemon streamed that output tothe Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashFor more examples and ideas, visit: http://docs.docker.com/userguide/

Understand containers and images

Take the command docker run hello-world as an example:

A container is a simplified Linux operating system, and an image is a collection of software loaded into the container. after this command is executed, Docker will perform the following actions in sequence:

A. Check whether the hello-world image is installed.
B. If the image is not installed, download the image from the Docker Hub
C. load the image to the container and run it.

Create a Doker PHP container and enable the PHP development environment

Docker Hub has images provided by individual developers, official images uploaded by companies and organizational structures. you can use Docker Hub images or local private images (such as local.registry.com: 5000/php ). Taking the establishment of the PHP development environment as an example, we will continue to describe how to use Docker commands.

Here, we use a self-built private image (which has been integrated with Linux + PHP + Apache). The private Image address is 172.16.100.71: 5000/php.

1. Set host for Windows and boot2docker VM

A. set a Windows host

In Windows, the local host is set to facilitate operations at the CMD command prompt. If you operate in Git Bash, you can skip the local host settings in Windows.

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

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

B. set the host of the boot2docker virtual machine

Run the boot2docker ssh command to enter the VM and then run the following command:

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

You can also use the combined command:

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

2. check the Environment variables

In Git Bash, enter:

export

Check whether the environment variables have been set automatically: DOCKER_HOST, DOCKER_CERT_PATH, DOCKER_TLS_VERIFY

Boot2docker shellinit can display the environment variables of the Docker client, so you can use the following command to automatically set the environment variables

eval"$(boot2docker shellinit)"

If this command cannot be set successfully, enter the following command to manually add it:

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

Enter export to check whether the write is successful.

To enable the Docker command in Windows CMD, type 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

Enter set to check whether the write is successful.

However, the environment variables set through the set command are temporarily valid and do not work when the cmd command line window is closed.

The permanent environment variables can be set as follows: "Computer-properties-advanced system settings-advanced-environment variables". create the preceding three system variables and enter the corresponding values. After the settings are complete, open CMD again to take effect.

In addition, if you want to run commands such as boot2docker ssh in CMD, you also need to set environment variables related to Git. The method is:

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

The permanent environment variable setting method is the same as above. append the following directory to the PATH field of the system variable (the specific directory is added according to the Git installation directory)

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

Then restart cmd to take effect.

3. set-insecure-registry options

From docker 1.3.1, connection to insecure private images is not allowed by default. To download a self-built private image, you must set it as follows:

boot2docker sshsudo vi /var/lib/boot2docker/profile

Add a row

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

Save and restart the docker service:

sudo /etc/init.d/docker restart

You can also merge operations in Git Bash:

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

Note: private Image addresses such as local.registry.com: 5000 can also be replaced by IP addresses.
Tee command parameter-a is used to append content to the file as needed.

The sudo/etc/init. d/docker restart command sometimes fails to be restarted, so we can use the following command to observe the docker process information:

ps -ef |grep docker

If the PID of the docker main process (/usr/local/bin/docker) is small and runs for a long time, the restart is not successful. You need to force the process to be killed and then restart.

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

Finally, run the ps-ef | grep docker command to check the process number and running time again to ensure the docker restart is successful.

ps -ef |grep dockerexit

4. download the private image to your local device.

docker pull local.registry.com:5000/php

Before running the image, download it to your local computer. If an error is reported, follow the previous steps or troubleshooting steps to solve the problem. then proceed with the subsequent steps.

5. check and set virtual machine shared folders

By default, VirtualBox uses the host directory C: \ Users as the shared folder and automatically mounts it to the virtual machine c/Users path. Therefore, we usually choose to place the data in the C: \ Users Directory of the host machine, and then mount the data to the container through the docker command. However, for Windows users, the C drive is often used as the system disk. it is dangerous to store the key data on the C drive. if the Windows system is damaged and cannot be started, data may be lost.

Therefore, we thought: can we add shared folders under other drive letters and mount them to containers?

Of course !!! The steps are a little complicated. let's continue.

After trying to create a shortcut pointing to another drive letter shared folder in the C: \ Users Directory, this method does not work.

The following are the correct steps:

Open the boot2docker virtual machine GUI, click "settings"-"shared folder", right-click "Add shared folder" in the "fixed allocation" menu ",

A. run boot2docker ssh to enter the virtual machine. first, confirm the directory to be mounted. if the directory does not exist, manually create it:

boot2docker sshsudo mkdir -p /f/projects/phpdev

B. After creating the directory to be mounted, run the following command to mount the shared folder.

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

Or

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

For example:

After the mount is complete, exit and restart boot2docker ssh to enter the virtual machine and check whether the shared folder of the host is synchronized to the mounted directory.

As you can see, the files/folders under the Local Directory F: \ projects \ phpdev of the host have been synchronized to the Mount Directory of the current virtual machine, that is, the/f/projects/phpdev path.

Since the docker container in step 6 is to mount/f/projects/phpdev to the/var/www/html path of the Container Linux environment, this step is to prepare for the next step.

Generally, data is not permanently stored in the container environment created by docker to ensure data security and integrity. A common method is to map the file system of the local host to the file system of the container environment. This ensures that the data generated in the container environment is directly stored on the disk of the user host, data will not be lost because the container is damaged or the container is not persisted in time.

According to the official boot2docker (https://github.com/boot2docker/boot2docker) description, boot2docker has a built-in client Enhancement Package (VirtualBox Guest Additions) dedicated for virtual machine folder sharing ).

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

Mount Users to/Users
/Users mount to/Users
Mount c/Users to/c/Users
Mount/c/Users to/c/Users
C:/Users mount to/c/Users

To share other file paths, run the following command:

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

Or

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

Note: The Linux command id can be used to view the UID (corresponding to/etc/passwd) and GID (corresponding to/etc/group) of the user)

However, if Windows is restarted, these settings will be cleared and Mount again (of course, restarting the boot2docker-vm will also clear all configuration data ). If you do not want to manually mount each time, you can add one in/etc/fstab.

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

Or

your-other-share-name /some/mount/location vboxsf defaults 00

In this way, automatic mounting is enabled (the client enhancement package VirtualBox Guest Additions needs to be installed ).

After the manual mounting command is executed, the contents of the shared folder can be displayed in the/some/mount/location directory.

Because boot2docker itself is a virtual machine and docker is also a virtual machine environment, you need to use docker run-v path1: path2 to mount it successfully. you need to perform two steps of ING: the shared folder is first mounted to the boot2docker virtual machine by the host machine, and then to the docker container environment by the boot2docker virtual machine.

Create a Mount directory before mounting:

sudo mkdir -p /some/mount/location

Then run the mount command.

Unmount the shared folder and run the sudo umount-f/projects/phpdev command.

Note:

To unmount a shared folder, you need to exit the Mount directory before uninstalling it. Otherwise, an error is returned:
Umount: can't forcibly umount/f/projects/phpdev: No such file or directory

At the same time, be sure to write the correct command to uninstall the directory. Note the slash/before the drive letter F. If the directory to be detached has not been mounted, an error will be reported:
Umount: can't forcibly umount/f/projects/phpdev: Invalid argument

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

Create and run a container based on the local private Image (Linux + Apache + PHP integrated image:

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

Port 80 is the default port for HTTP/Nginx, and port 22 is the default port for Linux SSH. Later, mount the local directory/f/projects/phpdev of the host to the container.

Note:

If you run the command in Git bash in Windows, an error is returned because msysgit will automatically convert directories such as/c/Users to c: \ Users. Therefore, a double slash is required, run the following command in Git bash:

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

Then, run the docker ps command to view the currently running container.

$ boot2docker.exe ip192.168.59.103

We can access the current php container through ssh, or use SSH tools such as XShell to connect.

The SSH logon command is:

ssh -p 2222 root@192.168.59.103

Note: the account and password of boot2docker ssh are user/docker, and the private image is root/hellonihao.

After logging on to SSH, you can see the familiar Linux directory structure.

If the phpdev folder does not exist locally, a new phpinfo. php test file is created in this directory to output php configuration information.

The host machine of Docker is a virtual machine of boot2docker. Therefore, you need to use the ip address of the virtual machine for access. the ip address obtained is the boot2docker ip address.

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

For example, to create a container and a data volume/data based on the basic centos image, run the following command:

$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

Run the following command to mount the host directory to a data volume:

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

Note: In Git Bash, a double slash is required, that is:

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

With other common commands:

Docker rm-f php
Docker ps-l
Docker images-
Docker rmi
Docker stop
Docker run
Docker kill

The above describes how to install docker for Windows and how to use docker. If you have any mistakes or omissions, please leave a message to correct them and study docker together.

The next article will share with you how to handle common errors during docker installation and use.

References:

Http://docs.docker.com/userguide/ docker official documentation-User Guide"
Https://github.com/boot2docker/boot2docker "Boot2docker official documentation"
Http://blog.pavelsklenar.com/5-useful-docker-tip-and-tricks-on-windows/

This article is from the CSDN blog. For more information, see the source. thank you!

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the installation of Docker for Windows and the establishment of the Linux + PHP development environment (1), including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.