50 lines
1.8 KiB
Markdown
50 lines
1.8 KiB
Markdown
# 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`
|
|
* 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:
|
|
|
|
```Dockerfile
|
|
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 container
|
|
* `volumes` set for mounting volume, which we directly mount source code into container working directory
|
|
* `5000: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
|
|
|
|
1. `docker-compose csharp`, where `csharp` is the service name defined in docker-compose file
|
|
2. `docker-compose run -d csharp` to start container
|
|
3. 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
|
|
|
|
1. In new created attached VSCode window `dotnet new webapp` to create .NET app source code, these source code are all `root` based
|
|
2. Modify the source code by adding `.UseUrl("http://*:5000")` to create a simple website in `Program.cs`
|
|
3. Build the webapp by `dotnet build` in attached VSCode
|
|
4. Run webapp by `dotnet run` in attached VSCode, we can now view the web in host via `localhost:5000`
|
|
|
|
Further detail can be referred in:
|
|
* [ASP.NET Core in a container](https://code.visualstudio.com/docs/containers/quickstart-aspnet-core) |