Win7安装Docker | 少将全栈
  • 欢迎访问少将全栈,学会感恩,乐于付出,珍惜缘份,成就彼此、推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 吐槽,投稿,删稿,交个朋友
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏少将全栈吧

Win7安装Docker

点滴 admin 9年前 (2016-05-12) 5133次浏览 已收录 扫描二维码

        最开始接触Docker是一两年前了,认识了运维大神烈火(就职某知名IT公司),BatchShell的作者,此软件可以批量操作多台服务器,软件还是很不错的,可以给运维工程师节约很多时间。运维本来就好闲的赶脚,一周工作几个小时的样子,其他时间要么学习,要么就满世界的跑。。。(目前了解到的和接触到的),烈火推荐我去了解学习docker,那个时候win版好像还没有出。

        现在工作桌旁边的同事就是做运维的,上周远程配置服务器,在配置集群,动了网卡,无法连接上了,然后就出差去本地解决,要坐好几个小时的车,听着都累哈

        由于只是了解Docker,目前先在win7上使用Docker

        Docker Toolbox下载地址:Docker Toolbox

Win7安装Docker

        用win7安装Docker,其中的坑就是virtualbox,建议安装4.3.12版本的。

        如果安装的版本太高,会出现各种问题,另外android的虚拟机也无法正常打开。各种搜索还是无法解决。之后干脆就使用这个版本,一直还比较稳定,没有那么多烦恼。

        Win7安装Docker

        没事还是多看官网文档吧,少走弯路,哈哈哈。

        https://docs.docker.com/engine/installation/windows/

        详细安装教程参考官方文档如下:

Installation

If you have VirtualBox running, you must shut it down before running the installer.

  1. Go to the Docker Toolbox page.

  2. Click the installer link to download.

  3. Install Docker Toolbox by double-clicking the installer.

    The installer launches the “Setup – Docker Toolbox” dialog.

    Win7安装Docker

  4. Press “Next” to install the toolbox.

    The installer presents you with options to customize the standard installation. By default, the standard Docker Toolbox installation:

    • installs executables for the Docker tools in C:Program FilesDocker Toolbox
    • install VirtualBox; or updates any existing installation
    • adds a Docker Inc. folder to your program shortcuts
    • updates your PATH environment variable
    • adds desktop icons for the Docker Quickstart Terminal and Kitematic

    This installation assumes the defaults are acceptable.

  5. Press “Next” until you reach the “Ready to Install” page.

    The system prompts you for your password.

    Win7安装Docker

  6. Press “Install” to continue with the installation.

    When it completes, the installer provides you with some information you can use to complete some common tasks.

    Win7安装Docker

  7. Press “Finish” to exit.

Running a Docker Container

To run a Docker container, you:

  • Create a new (or start an existing) Docker virtual machine
  • Switch your environment to your new VM
  • Use the docker client to create, load, and manage containers

Once you create a machine, you can reuse it as often as you like. Like any VirtualBox VM, it maintains its configuration between uses.

There are several ways to use the installed tools, from the Docker Quickstart Terminal or from your shell.

Using the Docker Quickstart Terminal

  1. Find the Docker Quickstart Terminal icon on your Desktop and double-click to launch it.

    The application:

    • Opens a terminal window
    • Creates a default VM if it doesn’t exist, and starts the VM after
    • Points the terminal environment to this VM

    Once the launch completes, you can run docker commands.

  2. Verify your setup succeeded by running the hello-world container.

$ docker run hello-world
Unable to find image ’hello-world:latest’ locally
511136ea3c5a: Pull complete
31cbccb51277: Pull complete
e45a5af57b00: Pull complete
hello-world:latest: The image you are pulling has been verified.
Important: image verification is a tech preview feature and should not be
relied on to provide security.
Status: Downloaded newer image for hello-world:latest
Hello 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 from the Docker Hub.
   (Assuming it was not already locally available.)
3. The Docker daemon created a new container from that image which runs the
   executable that produces the output you are 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 an Ubuntu container with:
$ docker run -it ubuntu bash

For more examples and ideas, visit:
http://docs.docker.com/userguide/

Using Docker from Windows Command Prompt (cmd.exe)

  1. Launch a Windows Command Prompt (cmd.exe).

    The docker-machine command requires ssh.exe in your PATH environment variable. This .exe is in the MsysGit bin folder.

  2. Add this to the %PATH% environment variable by running:

    set PATH=%PATH%;"c:Program Files (x86)Gitin" 
  3. Create a new Docker VM.

    docker-machine create --driver virtualbox my-default Creating VirtualBox VM...
    Creating SSH key... Starting VirtualBox VM... Starting VM... To see how to connect Docker to this machine, run: docker-machine env my-default
  1. The command also creates a machine configuration in theC:USERSUSERNAME.dockermachinemachines directory. You only need to run the create command once. Then, you can use docker-machine to start, stop, query, and otherwise manage the VM from the command line.

  2. List your available machines.

    C:Usersmary> docker-machine ls
    NAME                ACTIVE   DRIVER       STATE     URL                         SWARM
    my-default *        virtualbox   Running   tcp://192.168.99.101:2376 

    If you have previously installed the deprecated Boot2Docker application or run the Docker Quickstart Terminal, you may have a dev VM as well.

  3. Get the environment commands for your new VM.

    C:Usersmary> docker-machine env --shell cmd my-default 
  4. Connect your shell to the my-default machine.

    C:Usersmary> eval "$(docker-machine env my-default)" 
  5. Run the hello-world container to verify your setup.

    C:Usersmary> docker run hello-world 

Using Docker from PowerShell

  1. Launch a Windows PowerShell window.

  2. Add ssh.exe to your PATH:

    PS C:Usersmary> $Env:Path = "${Env:Path};c:Program Files (x86)Gitin" 
  3. Create a new Docker VM.

    PS C:Usersmary> docker-machine create --driver virtualbox my-default 
  4. List your available machines.

    C:Usersmary> docker-machine ls
    NAME                ACTIVE   DRIVER       STATE     URL                         SWARM
    my-default *        virtualbox   Running   tcp://192.168.99.101:2376 
  5. Get the environment commands for your new VM.

    C:Usersmary> docker-machine env --shell powershell my-default 
  6. Connect your shell to the my-default machine.

    C:Usersmary> eval "$(docker-machine env my-default)" 
  7. Run the hello-world container to verify your setup.

    C:Usersmary> docker run hello-world 

Learn about your Toolbox installation

Toolbox installs the Docker Engine binary in the C:Program FilesDocker Toolboxdirectory. When you use the Docker Quickstart Terminal or create a default VM manually, Docker Machine updates theC:USERSUSERNAME.dockermachinemachinesdefault folder to your system. This folder contains the configuration for the VM.

You can create multiple VMs on your system with Docker Machine. Therefore, you may end up with multiple VM folders if you have created more than one VM. To remove a VM, use the docker-machine rm <machine-name> command.

Migrate from Boot2Docker

If you were using Boot2Docker previously, you have a pre-existing Dockerboot2docker-vm VM on your local system. To allow Docker Machine to manage this older VM, you can migrate it.

  1. Open a terminal or the Docker CLI on your system.

  2. Type the following command.

    $ docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm docker-vm 
  3. Use the docker-machine command to interact with the migrated VM.

The docker-machine subcommands are slightly different than the boot2dockersubcommands. The table below lists the equivalent docker-machine subcommand and what it does:

boot2docker docker-machine docker-machine description
init create Creates a new docker host.
up start Starts a stopped machine.
ssh ssh Runs a command or interactive ssh session on the machine.
save Not applicable.
down stop Stops a running machine.
poweroff stop Stops a running machine.
reset restart Restarts a running machine.
config inspect Prints machine configuration details.
status ls Lists all machines and their status.
info inspect Displays a machine’s details.
ip ip Displays the machine’s ip address.
shellinit env Displays shell commands needed to configure your shell to interact with a machine
delete rm Removes a machine.
download Not applicable.
upgrade upgrade Upgrades a machine’s Docker client to the latest stable release.

Upgrade Docker Toolbox

To upgrade Docker Toolbox, download and re-run the Docker Toolbox installer.

Container port redirection

If you are curious, the username for the Docker default VM is docker and the password is tcuser. The latest version of docker-machine sets up a host only network adaptor which provides access to the container’s ports.

If you run a container with a published port:

$ docker run --rm -i -t -p 80:80 nginx 

Then you should be able to access that nginx server using the IP address reported to you using:

$ docker-machine ip 

Typically, the IP is 192.168.59.103, but it could get changed by VirtualBox’s DHCP implementation.

Note: There is a known issue that may cause files shared with your nginx container to not update correctly as you modify them on your host.

Login with PUTTY instead of using the CMD

Docker Machine generates and uses the public/private key pair in your%USERPROFILE%.dockermachinemachines<name_of_your_machine> directory. To log in you need to use the private key from this same directory. The private key needs to be converted into the format PuTTY uses. You can do this with puttygen:

  1. Open puttygen.exe and load (“File”->“Load” menu) the private key from (you may need to change to the All Files (*.*) filter)

    %USERPROFILE%.dockermachinemachines<name_of_your_machine>id_rsa 
  2. Click “Save Private Key”.

  3. Use the saved file to login with PuTTY using docker@127.0.0.1:2022.

Uninstallation

You can uninstall Docker Toolbox using Window’s standard process for removing programs. This process does not remove the docker-install.exe file. You must delete that file yourself.

喜欢 (0)
[🍬谢谢你请我吃糖果🍬🍬~]
分享 (0)
关于作者:
少将,关注Web全栈开发、项目管理,持续不断的学习、努力成为一个更棒的开发,做最好的自己,让世界因你不同。