Visual Studio For Mac Docker

  1. Xamarin Studio was the de facto IDE for developing cross platform mobile apps on a Mac. Visual Studio for Mac which was launched in late 2016, replaced Xamarin Studio. While Xamarin Studio was a mobile first IDE, its successor is a mobile first and cloud first IDE that supports various workloads which weren’t present in XS.
  2. Missing Add Docker Support. Reported by Mike Palmer Feb 19 at 10:48 AM visual studio for mac. Upgraded to the new version of Visual Studio for Mac and the Add Docker Support menu item is missing. Reverted back to v12, created WebAPI and menu item is available. Rolled forward, same exercise and it is missing.
-->

As we have Visual Studio 2017 for Mac, what shall we check to connect to a Docker sqlserver container. Container was set up and running with successful connection through the Terminal commands, but not working using the application with connectionstring. Xamarin Studio was the de facto IDE for developing cross platform mobile apps on a Mac. Visual Studio for Mac which was launched in late 2016, replaced Xamarin Studio. While Xamarin Studio was a mobile first IDE, its successor is a mobile first and cloud first IDE that supports various workloads which weren’t present in XS.

Studio

Visual Studio For Mac Docker Support

This tutorial shows how to run an ASP.NET Core app in Docker containers.

In this tutorial, you:

  • Learn about Microsoft .NET Core Docker images
  • Download an ASP.NET Core sample app
  • Run the sample app locally
  • Run the sample app in Linux containers
  • Run the sample app in Windows containers
  • Build and deploy manually

ASP.NET Core Docker images

For this tutorial, you download an ASP.NET Core sample app and run it in Docker containers. The sample works with both Linux and Windows containers.

The sample Dockerfile uses the Docker multi-stage build feature to build and run in different containers. The build and run containers are created from images that are provided in Docker Hub by Microsoft:

  • dotnet/core/sdk

    The sample uses this image for building the app. The image contains the .NET Core SDK, which includes the Command Line Tools (CLI). The image is optimized for local development, debugging, and unit testing. The tools installed for development and compilation make this a relatively large image.

  • dotnet/core/aspnet

    The sample uses this image for running the app. The image contains the ASP.NET Core runtime and libraries and is optimized for running apps in production. Designed for speed of deployment and app startup, the image is relatively small, so network performance from Docker Registry to Docker host is optimized. Only the binaries and content needed to run an app are copied to the container. The contents are ready to run, enabling the fastest time from Docker run to app startup. Dynamic code compilation isn't needed in the Docker model.

Prerequisites

  • Docker client 18.03 or later

    • Linux distributions

Download the sample app

  • Download the sample by cloning the .NET Core Docker repository:

Run the app locally

  • Navigate to the project folder at dotnet-docker/samples/aspnetapp/aspnetapp.

  • Run the following command to build and run the app locally:

  • Go to http://localhost:5000 in a browser to test the app.

  • Press Ctrl+C at the command prompt to stop the app.

Run in a Linux container

  • In the Docker client, switch to Linux containers.

  • Navigate to the Dockerfile folder at dotnet-docker/samples/aspnetapp.

  • Run the following commands to build and run the sample in Docker:

    The build command arguments:

    • Name the image aspnetapp.
    • Look for the Dockerfile in the current folder (the period at the end).

    The run command arguments:

    • Allocate a pseudo-TTY and keep it open even if not attached. (Same effect as --interactive --tty.)
    • Automatically remove the container when it exits.
    • Map port 5000 on the local machine to port 80 in the container.
    • Name the container aspnetcore_sample.
    • Specify the aspnetapp image.
  • Go to http://localhost:5000 in a browser to test the app.

Run in a Windows container

  • In the Docker client, switch to Windows containers.

Navigate to the docker file folder at dotnet-docker/samples/aspnetapp.

  • Run the following commands to build and run the sample in Docker:

  • For Windows containers, you need the IP address of the container (browsing to http://localhost:5000 won't work):

    • Open up another command prompt.

    • Run docker ps to see the running containers. Verify that the 'aspnetcore_sample' container is there.

    • Run docker exec aspnetcore_sample ipconfig to display the IP address of the container. The output from the command looks like this example:

  • Copy the container IPv4 address (for example, 172.29.245.43) and paste into the browser address bar to test the app.

Build and deploy manually

In some scenarios, you might want to deploy an app to a container by copying to it the application files that are needed at run time. This section shows how to deploy manually.

  • Navigate to the project folder at dotnet-docker/samples/aspnetapp/aspnetapp.

  • Run the dotnet publish command:

    The command arguments:

    • Build the application in release mode (the default is debug mode).
    • Create the files in the published folder.
  • Run the application.

    • Windows:

    • Linux:

  • Browse to http://localhost:5000 to see the home page.

X Code

To use the manually published application within a Docker container, create a new Dockerfile and use the docker build . command to build the container.

The Dockerfile

Here's the Dockerfile used by the docker build command you ran earlier. It uses dotnet publish the same way you did in this section to build and deploy.

Visual Studio For Mac

Additional resources

  • ASP.NET Core Docker sample (The one used in this tutorial.)

Next steps

Visual Studio For Mac Docker Debugging

In this tutorial, you:

  • Learned about Microsoft .NET Core Docker images
  • Downloaded an ASP.NET Core sample app
  • Run the sample app locally
  • Run the sample app in Linux containers
  • Run the sample with in Windows containers
  • Built and deployed manually

Microsoft Visual Studio For Mac

The Git repository that contains the sample app also includes documentation. For an overview of the resources available in the repository, see the README file. In particular, learn how to implement HTTPS: