How to Use Docker on Windows

How2UseDocker_Windows

Difficulty: Beginner

Prerequisites

To follow this tutorial, you need a working installation of Windows 7 or 8 on your computer.

How Docker works and how to make it work on windows

Before jumping into the installation process, let’s see how Docker works in order to understand what we’ll need to do to make it work on Windows.
We must first view Docker as both a server and a client.

The server lets us build, download, start and stop images or containers.
The client is just a command line tool that will allow us to communicate with the API of the server.

Here is what it looks like on Linux :

Diagram_linux

The purpose of this tutorial is to use Windows to run both our Docker client and server; therefore using it as a Docker host. To do that we are going to use Boot2docker

Boot2docker

Since we aren’t using Linux, it is not possible (yet) to use Docker natively. We are going to need some sort of lightweight VM that emulates a Docker Host.

This is what Boot2docker is for.

Boot2docker is a lightweight Linux distribution based on Tiny Core Linux made specifically to run Docker containers. It runs completely from RAM, weighs ~27MB and boots in ~5s

Source : boot2docker.io

Basically, Boot2Docker will encapsulate our Docker server into a virtual machine and let us access it through the Windows Docker client.

Diagram_win

Installation

  • First, download and run the latest version of Boot2docker here. The Windows version of Boot2docker contains the Docker for Windows installer. It will install a set of tools (VirtualBox, Boot2docker ISO, MSYS-git UNIX tools) to help us run Docker.
  • We now have a new shortcut on the Desktop called Boot2Docker Start. This shortcut is a shell script that will initiate the Boot2docker virtual machine and also the docker client. It will ask you for a ssh passphrase; you can either type one or just hit enter.
    Boot2docker then starts initializing the VM and the Docker client. However, unlike Docker on OSX, we can’t use the Docker client directly from Windows but only from the Boot2docker VM.
    We are now logged into the boot2docker VM and ready to use Docker.

Running Docker containers

Now that the install process is finally finished, we have the ability to launch containers, pull images, etc. as if we were using Docker on Linux.

First, type :

docker

to ensure that everything is working.

Boot2docker comes with a sample image named hello-world that lets new users quickly launch a container. Let’s give it a try :

docker run hello-world

We should see a “hello world” message printed on the screen.

Port Redirection

Redirecting ports with Boot2docker is really easy. The command is the same as on Linux, i.e. by using the -p flag like this :

docker run -p PUBLIC_PORT:PRIVATE_CONTAINER_PORT IMAGE CMD

For instance, if we wanted to run the redis image on port 6379, we would run :

docker run -p 6379:6379 redis

The only thing that differs from running this command on Windows instead of Linux is that we will need the Boot2docker IP address in order to access that redis server.

In order to get it we can run the following command :

boot2docker ip

Sharing a Windows folder

This part will explain how to properly set up a shared folder between Windows and Boot2docker. However, as this feature is not officially included we will need to install additional tools.

First, we need to get cifs-utils on the Boot2docker VM

wget http://distro.ibiblio.org/tinycorelinux/5.x/x86/tcz/cifs-utils.tcz

tce-load -i cifs-utils.tcz

Then, we create a folder

mkdir /mnt/sharefolder

This will be used as a mount point for our shared folder.

We will then need to create and share a new folder on Windows. To keep it simple, let’s just share the folder with ourselves.

Finally, we mount the shared folder on the Boot2docker VM

sudo mount -t cifs //WINDOWS_IP/shared /mnt/sharefolder -o username=WINDOWS_USERNAME

We will be asked to enter our Windows password and the folder will be mounted.

This will allow us to create volume containers (instructions here) or share Dockerfiles between Windows and the VM for instance.

Further details on Boot2docker

User and password

We might need the username and the password of the Boot2docker user. By default the username is docker and the password is tcuser.

Upgrade Boot2docker

In order to upgrade Boot2docker:

  • Download the latest version of Docker for Windows and run the installer, after which the Boot2docker management tool is updated.

  • Upgrade the VM

boot2docker stop

boot2docker download

boot2docker start

Conclusion

The main goal of this tutorial was to explain how to install a working Docker environment on Windows using Boot2docker. However, with the recent announcements regarding Docker Windows Support on Azure and Windows Server, a cleaner way to run Docker without VMs may arise.

http://maximeheckel.com

Tagged with: , ,
Posted in Tutorial
30 comments on “How to Use Docker on Windows
  1. barhun says:

    one thing to note: boot2docker should be run as an administrator, otherwise some errors with inexplicit messages are encountered.

    you can also use boot2docker-powershell by henjuv instead, it’s pure powershell and doesn’t need msysgit to be installed on the computer.

    https://github.com/henjuv/boot2docker-powershell

  2. […] 《如何在Windows上使用Docker》:一篇初级教程,主要介绍了如何在Windows上使用Docker,评论中有读者提到boot2docker-powershell这个工具,感兴趣的读者可以自行尝试。 […]

  3. If you are on windows 8 and Hyper-V is enabled, you won’t be able to use boot2docker. You will need to manually create your VM. I use Powershell to set up a CoreOS Hyper-V Machine configured through cloud-config. I haven’t tried the recently released Windows client yet, so still using priviledged containers with cifs-utils running inside to access the windows folder. But even with a Docker client, I would not be able to run my python/node/… shell without cifs – thanks for this guide.

  4. moy says:

    is there any way to auto mount the shared folder when starting boot2docker?

  5. Leigh says:

    Its worth noting I had some huge problems trying to run docker on windows. Boot2docker would install OK with VritualBox 4.3.20. I could NOT run boot2docker or docker itself.

    It took me ages to figure out that I had uninstall VirtualBox 4.3.20 and use 4.3.12 instead which worked first time like a treat!

    So.. for Windows boot2docker only use VirtualBox 4.3.12.

  6. M.Mounir says:

    Sine boot2docker v1.3 and higher you have VirtualBox Guest Additions preconfigured to map the Linux /c/Users/ to c:\Users You can also just use the Windows Explorer to create this directory.

    You can access from docker to this folder by taping cd /c/Users/

  7. Vivek says:

    I am running boot2docker on Windows7 in a corporate environment. Boot2docker is unable to access the image download url from the company intranet and it ends with the below error –

    x509: certificate signed by unknown authority.

    I have the company certificates with me but I don’t know where should these certificates be configured in VM so that boot2docker will see it and reach to https url to download image. Can anyone please help !

  8. Krishna says:

    I have exactly same problem. I have a company laptop and I am not using VPN, but I still have the same problem. I am using external Wifi service.

  9. soumya mukherjee says:

    Thanks for the steps to install and run docker on windows env. Could you please share the steps to enable/open firefox through docker client too. As of now, it gives the message “Firefox not found”.

  10. Great howto. I’m an old hat at Linux, so this was simple and quick to get started.
    The next thing I tried was:
    docker run -it centos:7 bash
    and now I’m reading on how to add to the image…

  11. Edel says:

    Hi, I’ve been working with boot2docker in windows 8, sharing my app folder successfully, but for some reason the mapping stop working, when i try to list the content of my mapped folder boot2docker the process gets hang and i need to stop boot2docker and re-do all my mappings again.

    does anyone have had this issue?

  12. Shikha says:

    “`sudo mkdir /mnt/sharefolder“` worked.

  13. […] the Docker site installation documentation. Another nice and very to the point intro can be found here. Note that running Docker on Windows really involves quite some technology, but the installer […]

  14. […] part has been explained in the article dedicated to running Boot2Docker on Windows, take a look if you want to know more about […]

  15. Premkumar says:

    I have downloaded and installed the docker in my Windows machine. When I try to run the following command “docker run hello-world”, getting the following error :
    $ docker run hello-world
    Unable to find image ‘hello-world:latest’ locally
    Pulling repository hello-world
    FATA[0007] Get https://index.docker.io/v1/repositories/library/hello-world/images: EOF.

    Help me out !!!!!

  16. sandilya says:

    what is the WINDOWS_IP ??

  17. abdu chadili says:

    DOESN’T work n Windows 7, when we double click on the shortcut it clocks for a while and exits silently

  18. Las estrategias ciegas, en las que no debas meditar, sino solo proseguir instrucciones, no funcionan. que cotizan en la Bolsa de la ciudad de Londres.

    Son propiedad de financial times y de la bolsa del Los testimonios de nuestros clientes del servicio demuestran que brindamos el mejor servicio al cliente
    del servicio y ayuda profesional, en forma permanente.

  19. Jannie says:

    Hello, I think your blog may be having browser compatibility issues.
    Whenever I take a look at your site in Safari, it looks fine however, if opening in IE, it’s got some overlapping issues.
    I just wanted to provide you with a quick heads up!
    Apart from that, excellent blog!

  20. autoinfo.hu says:

    Estima que aparte de las disposiciones generales, cada línea puede tener sus condiciones, conque lo
    mejor es preguntar directamente con el distribuidor del servicio.

  21. gestapo says:

    I’m creating a new blog about literature ( what I’ve read, what I’m reading), but I’m having trouble thinking of a title. I like the idea of something having to do with an obsession with literature but I think bookophilia is on the average side. What do you think of Litophilia? Is it too similar to “lithophilia” Which means the love of stones? Any ideas? Thanks!.

  22. csbosss says:

    Question:

    when I use boot2Docker, can I still work on my laptop without over-controlling from Boot2Docker over my laptop resources??

    I just want to know this:
    q2) CAN WE consider boot2docker as hypervisor type 2 to be used for cloud?, or can I consider that laptop resources can’t be used by me since sources are full consumed

    I want to use two laptops to work for cloud and participate through docker as computing resource??

    any thought? it’s just lab experiment I need to do

  23. […] How to Use Docker on Windows […]

  24. […] How to Use Docker on Windows […]

  25. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is important and all. But think of if
    you added some great photos or video clips to give your
    posts more, “pop”! Your content is excellent but with pics and video clips, this site could
    definitely be one of the best in its niche. Good blog!

  26. Shashank G Bydher says:

    Docker toolbox for windows 7 is 70% of original software.I mean you cant make use of many commands in docker toolbox, those are not exist only.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories
%d bloggers like this: