Lots have been said in praise of docker. I agree with all most often named advantages, but I think one is really neglected to be named. Or maybe it is so obvious that I am the only guy who thinks it should be named explicitly. What can that be? As soon as you get basic docker skills your entry barrier to learn new trendy technology gets decimated. For every Redis, Mongo, akka.net, EventStore, Kafka, .Net Core, Ruby, Elixir, R, Python, Clojure and what have you – you can get started in seconds to minutes by delegating environment setup for each of these to docker system. No heavy environment setup, no missing dependencies, no accidental co-modification, no problems if your machine needs to reinstall OS – just pure engagement with what you actually want to do. And once you get there every taken step encourages you to take two more.
I’m by no means docker expert, but it has changed my professional life so much, that I promised myself that I will share some examples just of sheer gratitude.
Disclaimer: I will not explain what docker is and what is it used for. This is not description of what docker is, it’s a entry level tutorial for people who know that already and now want to try it out.
Part 1 shows how to get docker running on windows machine.
Running docker on Windows 10 machine (with docker-machine).
As of this moment (July 2016) there are two options available for Windows users:
- try out docker for windows Beta,
- stick with the way it was done till now – that is docker-machine.
Since I haven’t tried the first one till now, I’ll only describe how I’m using the second one. Docker-machine is docker dedicated wrapper around virtual machine that runs Linux and then docker on it. It sounds awfully complicated, but it’s not (in usage). See picture below to get it:
You can go and install everything manually, that is download docker-machine installer and make it run, but I recommend to use Chocolatey. It makes installation looks so simple:
choco install docker choco install docker-machine
I’ve first tried to make docker-machine work with Hyper-V, it worked but I had trouble sharing files from my physical machine with my docker machine (and therefore containers), and finally I’ve reverted to VirtualBox. For this to work I had to disable Hyper-V first. This is how you do it (as found here):
bcdedit /set hypervisorlaunchtype off
If you ever need it back on here’s how:
bcdedit /set hypervisorlaunchtype auto
Also make sure that virtualization is enabled in BIOS. After that’s done just install docker-machine and fire up your favorite console (I use ConEmu wrapped around PowerShell).
Let’s check how are we doing:
PS C:\Users\kamil_000> docker-machine status Stopped
You might have it running already, but if like me you don’t you have to run:
PS C:\Users\kamil_000> docker-machine start Starting "default"... (default) Check network to re-create if needed... (default) Waiting for an IP... Machine "default" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
and then let’s check the status again:
PS C:\Users\kamil_000> docker-machine status Running
That’s better. Now let’s configure our console to allow us to directly access docker:
PS C:\Users\kamil_000> docker-machine env Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": dial tcp 192.168.99.100:2376: i/o timeout You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'. Be advised that this will trigger a Docker daemon restart which will stop running containers.
Oh no! Something is wrong, but no biggy, it also says how to fix it. You might not experience this error at all (if that’s the case just skip this step). However if you do let’s follow recommended step to fix it:
PS C:\Users\kamil_000> docker-machine regenerate-certs Regenerate TLS machine certs? Warning: this is irreversible. (y/n): y Regenerating TLS certificates Waiting for SSH to be available... Detecting the provisioner... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon...
and than again
PS C:\Users\kamil_000> docker-machine env $Env:DOCKER_TLS_VERIFY = "1" $Env:DOCKER_HOST = "tcp://192.168.99.100:2376" $Env:DOCKER_CERT_PATH = "C:\Users\kamil_000\.docker\machine\machines\default" $Env:DOCKER_MACHINE_NAME = "default" # Run this command to configure your shell: # & "C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env | Invoke-Expression
ok, that’s better. It lets us know about some environmental variables and also tells us what to do to get the console configured. Let’s do that:
PS C:\Users\kamil_000> & "C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env | Invoke-Expression
Now you should be able to call docker:
PS C:\Users\kamil_000> docker Usage: docker [OPTIONS] COMMAND [arg...] docker daemon [ --help | ... ] docker [ --help | -v | --version ] A self-sufficient runtime for containers.
As a next step let’s make sure that we can actually download images (image means a template for container more or less in the same sense as class is template for object). We could just test it by downloading sample image:
PS C:\Users\kamil_000> docker pull hello-world
Or just trying to run hello-world instead only downloading it (executing following command implicitly includes pull command as written above):
PS C:\Users\kamil_000> docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly.
If you have any problems with pull command most likely your network is not configured properly on/for virtual machine. Make sure, that there is a bridged connection between your physical machine network card and VM network adapter. To do that do to Control Panel/Network and Internet/Network Connections, than Change adapter setting. You should see router icon like on the picture below and if you right-click and select properties you will be able to see all bridged cards.
If this bridge is not there just select two carts that should be constituting it, right click and say bridge connection.
Another quite common problem
If on running the docker commands you see something like this:
PS C:\Users\kamil_000> docker pull hello-world Using default tag: latest Warning: failed to get default registry endpoint from daemon (An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/info: open //./pipe/docker_engine: Nie można odnaleźć określonego pliku.). Using system default: https://index.docker.io/v1/ An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/images/create?fromImage=hellp-world%3Alatest: open //./pipe/docker_engine:
It means, that console you’re running this command from can’t get in connection with docker. This should help:
PS C:\Users\kamil_000> docker-machine regenerate-certs -f PS C:\Users\kamil_000> & "C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env | Invoke-Expression
This problem is likely to occur between restarts of docker-machine VM or physical host station. We just need to re-configure our console to make it find and be able to connect to docker again.
That’s it. We have docker up and running. In Part 2 (under construction) we will get few containers spinning and taking to each other.