It’s almost 2020, and as we approach the future that many of our favorite science fiction movies could only imagine, we hope that technology can save us from dystopian dependency hell. I know I’m dramatic, but in this post, I’ll show you how to cut the drama out of your .NET development environment. You’ll be able to share common environmental dependencies like databases, cloud emulators, and tools across multiple platforms, all in the spirit of peace and harmony.

Assumption

This post assumes you use Microsoft SQL Server and host your applications in Windows Azure. That said, this approach can work with other toolchains. Be creative and adapt away. We are also going to be using Linux images and hosts to run our dependencies.

The Goal

To have a development environment that works similarly, if not identically, across any modern operating system. What about Linux, macOS, Windows? YES!

Tools

The first thing you’ll need is the tools to make your new workflow work. Here are links to the following applications:

Docker

You’ll need Docker installed. Here are the guides for each OS.

Be sure to configure your Docker host instance appropriately based on the number of containers you need to run simultaneously. You can set the configuration of the Docker Engine in the Advanced section of the settings.

docker settings

Once you have Docker running, you can copy and paste the following Docker Compose file onto your machine. The file should be named docker-compose.yml.

version: '3.4'

services:
  mssql:
    image: "mcr.microsoft.com/mssql/server"
    container_name: mssql
    hostname: mssql
    environment:
      SA_PASSWORD: "Pass123!"
      ACCEPT_EULA: "Y"
    restart: always
    ports:
      - 11433:1433
  elasticsearch:
    image: "docker.elastic.co/elasticsearch/elasticsearch:6.8.5"
    container_name: elasticsearch
    hostname: elasticsearch
    environment:
      - discovery.type=single-node
    restart: always
    ports:
      - 9200:9200
      - 9300:9300
  kibana:
    image: "docker.elastic.co/kibana/kibana:6.8.5"
    container_name: kibana
    hostname: kibana
    restart: always
    ports:
      - 5601:5601
  azure_storage:
    image: "mcr.microsoft.com/azure-storage/azurite"
    container_name: azurite
    hostname: azurite
    restart: always
    ports:
      - 10000:10000

After creating the file, open a terminal window, and run the following commands:

> docker-compose pull
> docker-compose up -d

The first command makes sure you have the latest images on your machine for each dependency. In our case, we want the most recent Microsoft SQL Server, Elasticsearch, Kibana, and Azurite (an Azure Emulator). It’s really important you run with the -d flag, as this will start the containers in a detached mode, allowing you to continue using your terminal.

If you already had these images and containers on your machine, you can clean your environment using the following commands.

> docker rm $(docker ps -a -q)
> docker rmi $(docker images -q)

Be careful; these commands will remove all containers and images from your machine.

Note: If you already have these dependencies running on your host machine as services, it is best to disable or uninstall them entirely.

If all is successful, you should be able to run docker ps in your command-line tool and see the following results.

results of docker ps

.NET App Configuration

The next part is critical to your development success, how to use your new-found dependencies. The great thing about Docker is it is like any other dependency.

  "connectionStrings": {
    "sqlServer": "server=localhost,11433;database=<database name>;user=sa;password=Pass123!;",
    "blobStorage": "UseDevelopmentStorage=true;"
  }

In the example above, we’re able to connect to Microsoft SQL Server and the Azure Emulator.

Conclusion

Docker makes cross-platform work more accessible than ever. Using Docker doesn’t mean you have to go all-in and containerize everything. You can use it to power your dependencies while still utilizing the workflow you’ve become accustomed to. You can spend more time developing your applications and less time struggling with installers and host quirks. Additionally, many of our development tools have become cross-platform thanks to Electron, .NET Core, and Java. I hope you found this post helpful, and please feel free to share your Docker-Compose files.