Stranice

Friday 28 August 2015

Working with directories in Docker using Windows 7 x64

This example was performed by using Docker Windows CLI 1.8.1

I will use linux shell on Windows.
The easiest way to run a shell is by installing Git with Unix tools.

Mounting directories from Windows host to Docker

 We need to put our directories into c:\Users\ directory. 
 docs: https://docs.docker.com/userguide/dockervolumes/ 
(Mount a host directory as a data volume)

There is a slight change when working in shell that worked in my case is that extra / need to be put.
So the following command mounts a directory from a host 

docker run -v //c/Users/directory:/directory image-name command

note: the volume is mounted temporary, you need to copy is into other directory,
or you can use docker cp command to copy data from host to container

Running docker with working working directory

We have the same problem as when  mounting directory.
That means we need to add extra / to run a directory from the container.
If don't do it a directory from host machine will be demanded.

This is example for first level directory in docker image

docker run -d -w //directory docker-image command


For initial startup with docker toolbox in Windows 7
Docker-machine on Windows 7 x64 




Thursday 27 August 2015

docker-machine on Windows 7 x64

I suppose you would like to use Docker toolbox on Windows 7 x64.
Boot2Docker is deprecated and new way of using Docker on Windows is docker-machine command.

If you are following official documentation they use one very cool command that sets environment variables in your shell automatically eval "$(docker-machine env machine-name)".
And then you get an error:
'eval' is not recognized as an internal or external command,
operable program or batch file.

Well, you think that there must be a command that is not on the path.
Unfortunately this is not also the case.

Uh, another linux on the Windows system.

Solution is quite simple.
1. Install Git for windows (include Unix tools) and run command prompt
    Be sure to enable PATH for git commands  
2. run sh -li (interactive shell)
3. your command line will change into linux shell
4. run above mentioned command:
    eval "$(docker-machine env machine-name)"

I have found out that usually there are usually some missing steps in the tutorials.

Well, well, something is missing here.
It seems that machine name is missing..

Ok, here is complete example from creating a new machine and connecting to it.

1. c:\Users\Name\sh -li (runs shell)
2. Name@Computer-Name ~ docker-machine create --driver virtualbox dev
3. Name@Computer-Name ~ eval "$(docker-machine env dev)"

Now your console is ready to use docker command on dev machine