Code Monkey home page Code Monkey logo

dockerdevenv's Introduction

Instructions

Important: Create project using all lowercase letters or else bad things will happen.

Caution: Carefully distinguish your local VS Code instance from your Docker Dev Env instance.

Create new Project

mkdir dockerdevenvdemo
cd dockerdevenvdemo
dotnet new webapi
git init
dotnet new gitignore
code .

Add some code:

static string Hi() => "Welcome to my Minimal API implementation!";

app.MapGet("/hello", Hi).WithName(nameof(Hi));

await app.RunAsync();

Run the code.

Commit and publish to public repo dockerdevenvdemo

Create config files

  1. Dockerfile.dev
# https://hub.docker.com/_/microsoft-dotnet-sdk/
FROM mcr.microsoft.com/dotnet/sdk:7.0

RUN useradd -s /bin/bash -m vscode
RUN groupadd docker && usermod -aG docker vscode

USER vscode
  1. compose-dev.yaml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.dev
    entrypoint:
    - sleep
    - infinity
    init: true
    volumes:
    - type: bind
      source: /var/run/docker.sock
      target: /var/run/docker.sock
  1. Commit and Push.

Create Dev Env in Docker based on GitHub repo

Create a new dev env based on repo.

Enter repo URL https://github.com/Monte-Christo/dockerdevenvdemo.git to build image and run dev env container.

Connect to image with VS Code.

dotnet run

Install C# and Docker extensions manually.

To work with the repo

git config user.name "Edgar Knapp" 
git config user.email "[email protected]"

To get prompted to install recommended extensions upon container start, add file .vscode/extensions.json

{
    "recommendations": ["ms-dotnettools.csharp", "ms-azuretools.vscode-docker"]
}

Commit, sync, and quit VS Code.

Remove the dev env, create a new one.

Connect to it with VS Code and be prompted to install extensions.

Build and run a pre-built dev env image

In the local instance of VS Code:

Create a new branch pre-built. Change dev env config. Substitute block "build" with:

    image: edgarknapp/dockerdevenvdemo:latest

Commit and Sync

Right-click on Dockerfile and select Create Image... (provide tag edgarknapp/dockerdevenvdemo:latest.

Use Docker Dashboard to push image to DockerHub.

Create new Docker dev env based on git repo.

Run in VS Code

dotnet run

Share dev env with others

Have someone else check out your repo and run your Docker dev env.

Make changes, commit, and push on one machine.

kPull and check changes just made on the other.

Run multiple containers

Checkout master, create branch oracle. Publish branch.

Modify compose-dev.yaml. Append:

  database:
    image: oracledocker.azurecr.io/oracle-19-e
    environment:
      - ORACLE_SID=ORCL19CDB
      - ORACLE_PDB=ORCL19PDB1
      - ORACLE_PWD=test123$$
      - ORACLE_CHARACTERSET=WE8MSWIN1252
    volumes:
      - ~/oracle/oradata:/opt/oracle/oradata  # persistent oracle database data
      - ~/oracle/data-bridge:/data-bridge     # share data with the running container
      - ~/oracle/scripts:/opt/oracle/scripts  # run setup and startup scripts
    ports:
      - 1521:1521
      - 5500:5500

  seq:
    image: datalust/seq
    environment:
      - ACCEPT_EULA=Y
    volumes:
      - seq-storage:/data
    ports:
      - 5341:80

volumes:
  seq-storage:

Commit and push.

Login to Azure and ACR.

az login
az acr login --name oracledocker

Create new dev env using https://github.com/Monte-Christo/dockerdevenvdemo.git@oracle

Run app, explore DB in Bash CLI or SQL Developer, open http://localhost:5341 for Seq, inspect containers to check port assignments if connection fails.

Other Things to Try

  • Use other IDEs
  • Set up existing Azure DevOps repos as Docker dev envs.

dockerdevenv's People

Contributors

monte-christo avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.