How to get docker toolbox to work with .net core 2.0 project
Asked Answered
P

2

37

I'm getting an error trying to use the Docker functionality with my .NET core 2.0 project. I've been getting an error message saying

Visual Studio Container Tools requires Docker to be running before building, debugging or running a containerized project. For more info, please see: http://aka.ms/DockerToolsTroubleshooting

I followed the link, and upon realizing I have Windows 10 Home x64, and had to install Docker Toolbox, instead of Docker For Windows. Now it installed this executable called

Docker Quickstart Terminal

Is this the way one is supposed to start up that docker services? I have tried running this executable, and it seems to be working. My containers are running, but the error for Visual Studio Container Tools still persists.

What am I missing? Is having a version of windows higher than Home required in order to use the Docker Container Support within Visual Studio 2017?

UPDATE:

I tried to follow Quetzcoatl's suggestion, and I am still getting the same error within visual studio about those tools. Here is what I ran in the Docker Quick Start Terminal. I tried building the project after Visual Studio successfully opened the project, and was still getting the aforementioned error regarding the container tools.

My devenv.exe file is located at

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe

and my solution file is located at

D:\Development\Visual Studio\Musify2\Musify2\Musify2.sln

enter image description here

UPDATE 2:

I ran some of the suggested commands to try in the docker quickstart terminal and here were the results of those commands quetzenter image description here

Puccoon answered 24/8, 2017 at 19:46 Comment(3)
Off-topic but you'll have a better experience with Docker for Windows. Any chance of updating to Windows 10 pro instead?Hirudin
I was hoping to not have to shell out a $100 to upgrade. Again, according to the Windows documentation, Docker Toolbox is supposed to be sufficient to achieve the same result, however, this issue seems to suggest a different experience.Puccoon
Did you manage to get it running? I've just checked the screenshots and env-vars in the quickstart seem fine. If you run VS from inside of that, it should be able to read them, and then opening/building solution should be ok. Once you run VS, you can check it with ProcessHacker2 to see if VS process has inherited those env-vars from this console. If it did, the error should be gone, because it's all about those variables missing during the build.Maretz
M
27

With Docker Toolbox that's a little tricky, but actually the core-2.0 has nothing to do here. It's all about docker, docker-toolbox, and VS.

First of all:

Is this the way one is supposed to start up that docker services? I have tried running this executable, and it seems to be working.

Yes it is. If docker machine/services are running - that's good!

Now, you have to realize that in docker, typically, the information about how/where the docker is running is kept in environment variables. The quickstart script not only starts the docker-machine for you and checks some basic things, it also sets up a couple of environmental variables so that later all commands like docker, docker-compose etc know where to look for the docker virtual machine. In your/our case that information mainly consists of an IP of the VM and a port number that Docker listens on.

.. and your Visual Studio has no knowledge of that, because, I bet on that, you have ran the VisualStudio from StartMenu or from Desktop icon or by double-clicking on a solution file, so it had no chance of getting the environmental variables from quickstart console.

The solution is quite simple: make sure that VS gets that information. That is, make sure it gets that environmental variables, and make sure that it gets the fresh state of them, because the IP/port may fluctuate sometimes. So don't just copy them to your OS settings, because nothing will ever automagically refresh them..

The simplest way I found is to just close Visual Studio, run docker toolbox quickstart console, then run the VisualStudio from within that console, for example, for my VS2017 Community Edition:

Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
(.......snip..........)


                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

Start interactive shell
quetzalcoatl@LAP049 MINGW32 ~
$ /c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2017/Community/Common7/IDE/devenv.exe C:\\PATH\\TO\\MY\\SOLUTION.sln

The path is pretty long to write, even with TAB-completion, so usually make a tiny .sh script to run that for me.

BTW! Notice that the path to DEVENV must be unix-like (/c/Program\ Files...), because the mingw shell has to understand that, while the path to SOLUTION must be a normal windows path (c:\projects\foo\bar\..) because VisualStudio will try to read that after starting up.

Maretz answered 24/8, 2017 at 20:26 Comment(7)
@destructi6n: That .sh is literally just the last line from that screen at the end of the text.. /c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2017/Community/Common7/IDE/devenv.exe C:\\PATH\\TO\\MY\\SOLUTION.slnMaretz
I updated the original question. That didn't seem to work for me. I am still getting the same error within Visual StudioPuccoon
@destructi6n: (1) just to be clear, after running a VS from that console and after opening a solution, did get exactly the same message: Visual Studio Container Tools requires Docker to be running before (..) or different? (2) try running docker-machine status and docker container ls just before starting VS to see if it's connectable and running (3) also try docker-machine env to and set | grep DOCKER to see if all variables are set properly. set should show the same things as the first one. Later, the VS process should also have them, you can check ie. with ProcessHacker2Maretz
I updated the question @Maretz with results of the various commands you suggested. I will try ProcessHacker if everything looks to be working from the commands you suggested.Puccoon
got mine working. In the same console change directories to your project and run start <project.sln>Jenks
@Maretz instead of windows base container try linux base container with opening solution from console.Eichelberger
worked like a charm in Windows 8.1 Pro if someone's also interestingBuie
S
18

This is what I did to get vs 2017 working on windows 10 home with docker-toolbox. You follow this and i guarantee it will work. Note this only applies to windows 10 home which doesn’t support native docker for windows application:

  1. Install docker-toolbox on w10 home

  2. Run docker QuickStart terminal once to create the docker-machine. It takes a while. So be patient while it assigns the IP address and other things

  3. Once it’s done it will show you a command prompt. Type ‘docker-machine ip default’. Note down the ip address as you’re gonna need it later

  4. Close the QuickStart terminal window. That was just to initialize the boot2docker.iso image of a tiny Ubuntu linux server into virtualbox app (aka docker-machine aka default vm). If you’re not familiar with virtualization technology or oracle virtualbox stop reading and read up on them first and then start over. But if you do then gladly continue

  5. As I mentioned that your docker-machine instance is a Linux vm and therefore it’s obvious that you can only open projects built using .net core technology. Unfortunately for full .net framework you’ll either need to run Windows containers which are only available on windows 10 pro or build your own windows nano server or 2016 server vm on virtualbox and then use and follow steps for native docker for windows on dockers website. From here on the remainder of this answer will be helpful to those wanting to run core projects on Linux vm / docker-machine only

  6. Open windows power shell in administrator mode and type ‘docker-machine ls’ to confirm that default vm is running. Can also do ‘docker-machine status default’ and it should return ‘running’

  7. Now open virtualbox application which is running your default vm and click on settings. Open “shared drives” tab where you need to make sure ‘c:\Users’ folder on the host machine is mapped/mounted as ‘c/Users’ folder in the vm. Note that this step is super important and missing it will cause a lot of trouble getting it to work successfully

  8. Also a quick note that your solution/project/codebase MUST be saved under ‘c:\Users\‘ for it to work correctly. This is if you want to use it OOTB. I didn’t wanna waste time trying to mount a folder outside the permitted path. But if you’re the adventurous kind, please, by all means try to figure it out and let us know how you did

  9. Now as Quetzalcoatl correctly mentioned vs needs to know about this docker-machine. The only way that happens is if the environment variables are set. Therefore go ahead and run this command ‘docker-machine env default | Invoke-Expression’ in the powershell window. This is the magic sauce getting vs to behave nicely with docker-machine

  10. Go ahead and open vs normally either by dbl clicking your project solution or creating a new project/solution. In Powershell use the 'start' command to open your existing vs solution or a new vs instance. Pro-tip: if you create a new solution DO NOT select the option of Linux docker at the time of picking the project template type. You can totally add docker support once your solution is all setup and ready to go. Matter of fact leave it unchecked and let vs create your solution. This way you’ll get a chance to build and run your solution in IIS Express or Self-hosted modes to see if your core2.0 even works properly

  11. Once satisfied that everything worked and you saw the OOTB homepage now it’s time to add docker support by rt clicking on your project, hovering over Add and then clicking on ‘Add Docker Support’. This will create a new docker project (.dcproj) and add a bunch of docker related files

  12. Now I’m not gonna go into the nitty gritty of docker here however you’ll notice that your project is no longer the startup and the newly created docker project is. That’s perfectly normal and intended behavior. It means you’re setup and ready to fire up your app using docker containers. So go ahead and click on the ‘Docker’ button to see your hard work finally pay off. Again be patient as it takes a while to build images and spin up containers but once it’s done the vs will start and attach the debugger

  13. Here you’ll once again be disappointed and feel worthless because when the browser opens a new window or tab there’ll be a page unreachable error. The reason is the browser address points to localhost which is not the web server anymore. Your “web server” now is your docker container and therefore you’ll need to replace localhost with the IP address you retrieved above. Port number remains as it is. Once you submit the page you’ll be relieved and ecstatic to see the home page/route work. This should also enable debugging in vs. if for some reason it doesn’t then you may need to delete a folder called .vsdbg in c:\Users\ folder and rerun the application.

Scrofulous answered 30/1, 2018 at 6:26 Comment(5)
Thanks for the great tutorial. But still I had one more issue regarding powershell version not described here. #50085695Stratigraphy
yw. you should be able to edit my response. You can add the item below in a subtitle like things to watch out of or something.Scrofulous
Thanks for a great guide, there is a mistake in step 6 "Open windows power shell in administrator mode and type ‘docker-machine ls’ to confirm that default vm is running. Can also do ‘docker-machine status default’ and it should return ‘running’" powershell shouldn't be in Admin mode, it will not find any items in the ls as it will look for list of machines in admin mode but we installed them in user mode so if you open Power shell in normal mode then this step will work! @ScrofulousWino
"...powershell shouldn't be in Admin mode..." yes thats what I also found, please update this otherwise wonderful answer as this step eluded me somewhatGentle
@MaxCarroll Powershell in admin mode elevates permissions on certain commands which otherwise would not work. Can you describe what issue(s) you faced while trying above in admin mode? I'm not 100 convinced that admin mode was the cause of an issue for you. Hope you understand.Scrofulous

© 2022 - 2024 — McMap. All rights reserved.