1.8 KiB
1.8 KiB
Working with Codes
This tutorial talks about how to work inside container
- Update Docker Compose for dev need
- Entering dev container using docker compose
- Create source codes in dev container
- Installing dependencies
- C#
nuget
- Golang
go get
- Nodejs
npm install
- Python
pip install
- C#
- Compile and Run code
Benefit of dev with docker: decouple machine from dev environment, make host clean, and dev everywhere
Create C# website and run webapp
Update docker-compose file in csharp service
Adding following to services:
working_dir: /work
entrypoint: /bin/sh
stdin_open: true
tty: true
volumes:
- ./c#/src/:/work
ports:
- 5000:5000
where:
working_dir
set working directory in containervolumes
set for mounting volume, which we directly mount source code into container working directory5000:5000
, 1st one is the port on host, 2nd one is the exposed port in container
Build/Run dotnet image, and working it in VSCode
docker-compose csharp
, wherecsharp
is the service name defined in docker-compose filedocker-compose run -d csharp
to start container- In VScode, select the running container and click Attach Visual Studio Code, otherwise the normal vscode don't have privilege to run it later
Create & Run .NET webapp
- In new created attached VSCode window
dotnet new webapp
to create .NET app source code, these source code are allroot
based - Modify the source code by adding
.UseUrl("http://*:5000")
to create a simple website inProgram.cs
- Build the webapp by
dotnet build
in attached VSCode - Run webapp by
dotnet run
in attached VSCode, we can now view the web in host vialocalhost:5000
Further detail can be referred in: