Is it possible to run Docker Desktop with existing Linux VM? - docker

I have an Ubuntu VM using Hyper-V, specialized for server development with Docker daemon and docker compose already installed on it; is there any way to connect Docker Desktop on the Windows machine to the docker daemon in the Ubuntu VM?

Well, if I'm understanding correctly, you can't really 'connect' Windows Docker Desktop to the Linux Docker daemon; but, you can use various methods to control both of the daemons, and also link them into a single 'unit'.
To control them, my favorite way is to use Portainer (including the Portainer Agent), and to join the daemons I personally created a Docker Swarm for my small home network of Docker daemons on various OS's (I currently have 1 on Win 10, 1 on Raspberry Pi, and 1 on Kubuntu).
Docker Swarm is from my understanding, fading away these days though, in favor of Kubernetes. In my use case swarm was just easier, and had all I needed, so I opted for it over Kubernetes; you'll have to feel them both out on your own for your preference.

As mentioned in the other answer, this isn't really possible in docker for windows. You should probably migrate from your VM to WSL2 anyway now. It'll only get harder in the future. If your work is in git then you just have to reclone your repos and rebuild/pull your images.
However, I use docker professionally every day and I don't see a need for docker desktop. Which suggests that you probably don't need it either. What is it really? A UI that shows you what containers are running? Big deal -- I have docker ps to do that in bash...
I use windows because I'm working on a number of windows projects for clients and dual-boot into Linux for a reality check when windows is driving me insane or whenever I'm not being forced to run windows. I do all my server development in my pure-ubuntu environment (using K3D).
I'm also thinking of dumping ubuntu -- because of 'snap' -- I find it every bit as irritating as windows and I've been looking for an alternative for some time. I only use 3 GUI tools: a browser, postman, and IntelliJ -- if it wasn't for them I'd just install alpine on my laptop and be done.

Related

Dealing with dockers and containers in production

I am new to the containers topic and would appreciate if this forum is the right place to ask this question.
I am learning dockers and containers and I now have some skills using the docker commands and dealing with containers. I understand that docker has two main parts, the docket client (docker.exe) and the docker server (dockerd.exe). Now in the development life both are installed on my local machine (I am manually installed them on windows server 2016) followed Nigel Poulton tutorial here https://app.pluralsight.com/course-player?clipId=f1f27565-e2bf-4e58-96f3-bc2c3b160ec9. Now when it comes to the real production life, then, how would I configure my docker client to communicate with a remote docker server. I tried to make some research on the internet but honestly could not find a simple answer for this question. I installed docker for desktop on my windows 10 machine and noticed that it created a hyper-v machine which might be Linux machine, my understanding is that this machine has the docker server that my docker client interacts with but do not understand how is this interaction gets done.
I would appreciate if I get some guidance or clear answer to my inquiries.
In production environments you never have a remote Docker daemon. Generally you interact with Docker either through a dedicated orchestrator (Kubernetes, Docker Swarm, Nomad, AWS ECS), or through a general-purpose system automation tool (Chef, Ansible, Salt Stack), or if you must by directly ssh'ing to the system and running docker commands there.
Remote access to the Docker daemon is something of a security disaster. If you can access the Docker daemon at all, you can edit any file on the host system as root, and pretty trivially take over the whole thing. (Google "Docker cryptojacking" for some real-world examples.) In principle you can secure it with mutual TLS, but this is a tricky setup.
The other important best practice is that Docker images should be self-contained. Don't try to deploy a Docker image to production, and also separately copy your application code. The same Ansible setup that can deploy a Docker container can also install Node directly on the target system, avoiding a layer; it's tricky to copy application code into a Kubernetes volume, especially when Kubernetes pods can restart outside your direct control. Deploy (and test!) your images with all of the code COPYd in a Dockerfile, minimizing the use of bind mounts.

Stack difference between VirtualBox and Docker for Windows

Let say I want run Linux application on Windows laptop. (Let say the application is Mongo and it MUST be Linux Mongo). I have 2 options
I can use VirtualBox to run Linux virtual machine with application
I can use Docker for Windows to run Linux docker image with application
My question is: which solution is expected to have better performance? VirtualBox virtual machine has well known overhead, docker instance is a process with low overhead. But between laptop Windows and docker instance AFAIU Docker for Windows establish intermediate virtual machine with Linux (Hyper-V VM?)
Stack looks similar for both options. Could I say that some option has definitely better performance/resource requirements or it depends on specific details?
I would suggest use Docker instead of VirtualBox.
Docker is like independent platform, in future if you want to run on Mac, Linux or windows you just need to copy few files from one place to other to get it set up everything but with VirtualBox you need to copy whole image or re-configured everything.
Docker provides built-in support for all kind of base images, which will help you to get speedy development.
With the Docker, you can destroy or re-run image with few/one command.
Docker provides an easy way to map local folders with VirtualBox you need to configure that.
VirtualBox is heavy as compared with Docker.
In Docker, you will always get the fresh/clean environment if you decide to use Continuous Deployment.
Network mapping (port externalise) and many more things are easily available with Docker.
Again lastly Go with Docker :)
Hope this get you clear idea, Please let me know if you need any help to setup Docker environment for your development.

Windows and Linux Containers simultaneously Windows 10

I have a solution that includes about 5 containers. Most of them are alpine linux based, but one has to be a windows container. Unfortunately, the windows container relies on one of the linux containers for authentication and must be able to run alongside it. I am trying to set things up so I can develop locally with both containers running at the same time but I am having some trouble. Is it possible to run both Windows and Linux containers simultaneously on a Windows 10 Pro host using Docker for Windows (Hyper-V version)?
Essentially what I am looking for is the equivalent of running a docker compose file with both linux and windows containers in it (although everything I have researched says this isn't possible).
It looks like docker edge version 18.02 has the ability to run windows and linux containers next to each other using LCOW (Linux Containers on Windows). It hasn't made it into docker-compose yet, but I think it will very soon. Can't wait for the stable version to have this!

Docker: Why use Linux containers on Windows?

I am using Win 10 Pro N (Version 1709) as a development machine and Windows Server 2016 Standard (Version 1607) as production server.
I am currently developing an ASP.NET Core 2 application with MongoDb as database.
A couple days ago I first stumbled over the idea, to run MongoDb as a Docker image.
I don't have any experience with Docker so far, but I managed to switch from Linux containers (default) to Windows containers on Windows machines.
Was this a good decision? Or is there any reason why I should use Linux containers instead of Windows containers in my scenario?
What e.g. if I should decide to deploy my application to a Linux server some time? In this case, would it wiser to start with Linux containers right from the beginning?
Docker is not about virtualization but more about isolation.
A windows container will run on a windows host
A linux container will run on a linux host
Then some people wanted to run linux container on windows
First you needed to create a linux vm on windows to run the container
Now you can use LinuxKit to run the container but it's still a light VM
Then some people wanted to run windows container on linux
First you needed to create a windows vm on linux to run the container
Now you can use nothing more as of today
So the best bet is to start with a container aimed at your production servers
If you want to deploy to linux I would advise using linux containers since you then test a more similar setup and are more likely to find issues that will also show in your final deployment.
Other than that linux container technology is more mature and better supported than windows containers.

Running .Net Core in Docker in Windows Subsystem for Linux

Practically I want to play with .NET Core within Docker.
So as I understand it from this post to give myself the best flexibility I would install "Docker For Windows". Means I can ultimately deploy my .Core app to a container that is either a Windows or a Linux container. However the Linux container is still a Hyper-V managed Linux container.
1) Is there a way to instead use the Windows Subsystem for Linux (WSL) to do this in the Windows 10 Creators Update? Seems like less overhead than have Windows/Docker manage a separate Linux VM for me?
No, running Docker containers in WSL is not supported (link mine):
The docker engine is not a supported scenario in the short term. I would suggest hitting our User Voice page and upvoting Docker if you're looking to run the docker engine.
The docker client however should be running in build 14342. I have been able to run the docker client and connect to a docker engine running in a VM.
As to why it's not supported:
WSL is a clean-room kernel reimplementation. So it can't, for both technical and legal reasons, simply take the kernel components of Docker and "make it work". They would need to reverse-engineer years of ongoing kernel development and reimplement it. (Or take some other nontrivial approach.)

Resources