vscode Docker debugging csharp.listRemoteProcess failed - docker

I have a .Net 5 WebApi that i want to host and debug in Docker.
when i run the docker-compose the project launches correctly.
When attaching the debugger i get following error:
Running the contributed command csharp.listRemoteProcess failed
my docker file:
FROM mcr.microsoft.com/dotnet/sdk:5.0 as debug
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000/tcp
WORKDIR /app
COPY . /app
RUN apt-get update
RUN apt-get install -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg
ENTRYPOINT ["dotnet", "watch", "run", "--project myproject.csproj"]
the docker-compose file
version: '3.4'
services:
server:
build:
context: ./myproject
target: debug
ports:
- "5000:5000"
container_name: myproject
volumes:
- ./myproject:/app
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "csharp" ],
"debuggerPath": "/root/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
},
"sourceFileMap": {
"/work": "${workspaceRoot}/myproject/"
}
}
]
}

Related

Code Not Shown in VS code while debugging asp.net docker container

I am learning docker with asp.net core. Create a mvc application, dockerfile and docker-compose.yml file. I have docker file as below:
FROM mcr.microsoft.com/dotnet/sdk:7.0 as debug
#install debugger for NET Core
RUN apt-get update
RUN apt-get install -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg
RUN mkdir /app/
WORKDIR /app/
COPY ./src/testapp.csproj /app/testapp.csproj
RUN dotnet restore
COPY ./src/ /app/
RUN mkdir /out/
RUN dotnet publish --no-restore --output /out/ --configuration Release
EXPOSE 80
CMD dotnet run --urls "http://0.0.0.0:80"
Also, I have docker compose file as below:
version: "3.0"
services:
db:
image: postgres
restart: always
ports:
- "5432"
volumes:
- postgres:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: sachin
pg_admin:
image: dpage/pgadmin4
restart: always
ports:
- "5555:80"
volumes:
- pg_admin:/var/lib/pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: sachin.maharjan#dishhome.com.np
PGADMIN_DEFAULT_PASSWORD: password
web:
container_name: csharp
build:
context: .
target: debug
ports:
- "5000:80"
volumes:
- ./src:/app/
depends_on:
- db
volumes:
postgres:
pg_admin:
I have installed docker extension and C# extension in my vs code. I have lunch.js file inside .vscode folder.
The content of lunch.js:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "csharp" ],
"debuggerPath": "/root/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
},
"sourceFileMap": {
"/work": "${workspaceRoot}/src/"
}
},
]
}
The debugger stop at break point but it shows error like this.
Is this error with volume mapping or did I set up lunch.json wrong?
I noticed in lunch.json in the source map section, I mapped the wrong folder in local file system with file system with docker.
Previously, MapSetting section was like below:
"sourceFileMap":
{
"/work": "${workspaceRoot}/src/"
}
Then I change folder mapping with right one and erorr is solved.
"sourceFileMap": {
"/src": "${workspaceRoot}/src/"
}

Nestjs Docker Debug

I have a simple Dockerfile
FROM node:12.13-alpine As development
WORKDIR /usr/src/app
COPY package*.json ./
RUN apk add --no-cache bash && npm install --only=development
COPY . .
RUN npm run build
FROM node:12.13-alpine as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
my docker-compose is:
version: '3.7'
services:
main:
container_name: main
build:
context: .
target: development
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- ${SERVER_PORT}:${SERVER_PORT}
- 9229:9229
command: npm run start:debug
env_file:
- .env
Inside my package.json and script, I have:
"start:debug": "nest start --debug 0.0.0.0:9229 --watch"
I added the conf in my visual Studio Code (.vscode/launch.json)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"address": "127.0.0.1",
"port": 9229,
"sourceMaps": true,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app",
"skipFiles": ["<node_internals>/**"]
}
]
}
After that I can run docker-compose up --build and start my debugger but the code doesn't stop at my breakpoint.
I use Mac 12.6 and Docker version 20.10.13

Vapor App Local setup using Docker Compose

I used docker-compose for setting on my local machine.
Vapor app is working fine without using docker.
Environment
MacBook M1 Pro 14inch 2021
32GB Ram
But I got an error at Step 3
(Step 1, and 2 are ok, Swift compiler builds Vapor app successfully)
Received signal 4. Backtrace:
#!/bin/bash
echo "Step 1: Build Docker"
docker-compose -f local-docker-compose.yml build
echo "Step 2: Start dependencies"
docker-compose -f local-docker-compose.yml run --rm
echo "Step 3: Start Vapor App"
docker-compose -f local-docker-compose.yml up myapp-beta
# Build image
FROM --platform=linux/x86-64 swift:5.5-focal as build
RUN apt-get update -y \
&& apt-get install -y libsqlite3-dev
WORKDIR /build
COPY . .
RUN swift build \
--enable-test-discovery \
-c release \
-Xswiftc -g
# Run image
FROM --platform=linux/x86-64 swift:5.5-focal-slim
RUN useradd --user-group --create-home --home-dir /app vapor
WORKDIR /app
COPY --from=build --chown=vapor:vapor /build/.build/release /app
COPY --from=build --chown=vapor:vapor /build/Public /app/Public
# ARS RDS Environment ARG
ARG AWS_RDS_HOST
ARG AWS_RDS_PORT
ARG AWS_RDS_USER
ARG AWS_RDS_PASS
ARG AWS_RDS_DB
# SignInWithApple Environment ARG
ARG SIWA_ID
ARG SIWA_REDIRECT_URL
ARG SIWA_JWK_ID
ARG SIWA_PRIVATE_KEY
ARG SIWA_TEAM_ID
ARG SIWA_APP_BUNDLE_ID
# Set Environment
RUN echo "SIWA_ID=${SIWA_ID}" > .env.testing
RUN echo "SIWA_REDIRECT_URL=${SIWA_REDIRECT_URL}" >> .env.testing
RUN echo "SIWA_JWK_ID=${SIWA_JWK_ID}" >> .env.testing
RUN echo "SIWA_PRIVATE_KEY=${SIWA_PRIVATE_KEY}" >> .env.testing
RUN echo "SIWA_TEAM_ID=${SIWA_TEAM_ID}" >> .env.testing
RUN echo "SIWA_APP_BUNDLE_ID=${SIWA_APP_BUNDLE_ID}" >> .env.testing
RUN echo "DB_HOST=${AWS_RDS_HOST}" >> .env.testing
RUN echo "DB_PORT=${AWS_RDS_PORT}" >> .env.testing
RUN echo "DB_USER=${AWS_RDS_USER}" >> .env.testing
RUN echo "DB_PASS=${AWS_RDS_PASS}" >> .env.testing
RUN echo "DB_NAME=${AWS_RDS_DB}" >> .env.testing
USER vapor
EXPOSE 8080
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "local", "--hostname", "0.0.0.0", "--port", "8080"]
version: '3.7'
services:
myapp-beta:
depends_on:
- postgres
build:
context: .
args:
AWS_RDS_HOST: postgres
AWS_RDS_PORT: 5432
AWS_RDS_USER: test
AWS_RDS_PASS: test1228!1
AWS_RDS_DB: myapp_db
SIWA_ID: com.beta.myapp.service
SIWA_REDIRECT_URL: localhost:8080
SIWA_JWK_ID: JLJKLXXXX
SIWA_PRIVATE_KEY: xxxxxxx
SIWA_TEAM_ID: 9DFSXXXX
SIWA_APP_BUNDLE_ID: com.beta.myapp
dockerfile: local.Dockerfile
ports:
- '8080:8080'
postgres:
image: postgres
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test1228!1
POSTGRES_DB: myapp_db
start_dependencies:
image: dadarek/wait-for-dependencies
depends_on:
- postgres
command: postgres:5432
focal now includes arm64 arch that is necessary to run on M1. Here is the manifest:
docker manifest inspect swift:5.6-focal
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 1162,
"digest": "sha256:a34fb87d14544c49d5aa30c90fcf18347d301e7db1b1e917b23796d687c3e178",
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 1162,
"digest": "sha256:3708d167c44e62c928356c1aac9ba27ab77c7a4970d32dc8126a58ca5e2c0520",
"platform": {
"architecture": "arm64",
"os": "linux",
"variant": "v8"
}
}
]
}
You Dockerfile just needs to start with:
FROM swift:focal

Can not get cypress to work in docker container

I want to run cypress in docker container and for this purpose i created.
For this i followed some guides and tutorials
e2e directory that has Dockerfile
FROM cypress/base:14
WORKDIR /app
# dependencies will be installed only if the package files change
COPY package.json .
COPY cypress.json .
RUN npm install
RUN npx cypress open
RUN npx cypress verify
cypress.json
{
"baseUrl": "http://localhost:3000",
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/output.xml"
}
}
package.json
{
"name": "e2e",
"version": "1.0.0",
"description": "Cypress tests",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"private": true,
"devDependencies": {
"cypress": "9.5.0"
}
}
and .npmrc
registry=http://registry.npmjs.org/
save-exact=true
progress=false
package-lock=true
modified docker-compose.yml at the root to be
version: '3.8'
services:
nextjsApp:
// rest
cypress:
image: "cypress/included:3.2.0"
depends_on:
- nextjs
environment:
- CYPRESS_baseUrl=http://nextjs:3000
working_dir: /e2e
command: npx cypress run
volumes:
- ./:/e2e
networks:
backend:
external: true```
Running docker-compose build does not cause or show any errors
But when i run docker-compose up i get
cypress_1 | Could not find any tests to run.
cypress_1 |
cypress_1 | We looked but did not find a cypress.json file in this folder: /e2e
How can this be solved ?

Docker permission denied when writing files inside container

I'm trying to download a PDF and save it inside my application which is dockerized. The problem seems to be that I'm not allowed to write files inside the container. Here are the steps I took:
I first created a named volume myvol: docker volume create myvol. I then updated my docker-compose.yml file as follows:
version: "3"
services:
webpp:
container_name: webapp
image: webapp:latest
build: .
ports:
- "8000:8000"
volumes:
- myvol:/app
volumes:
myvol:
And for reference, my Dockerfile:
FROM python:3.7
WORKDIR /app
ADD ./requirements.txt .
RUN pip install -r requirements.txt
ADD . .
RUN groupadd -g 999 appuser && \
useradd -r -d /app -u 999 -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser
RUN mkdir webapp/_tmp; chmod a+rwx webapp/_tmp/
EXPOSE 8000
ENTRYPOINT ["python", "main.py"]
When I run my code, I get a permission denied. The same happens if I exec into the container and try to write something, or for example wget http://duck.com also gives me a Permission denied error.
I'm unsure what's wrong, as even docker inspect seems correct...
"Mounts": [
{
"Type": "volume",
"Name": "myvol",
"Source": "/var/lib/docker/volumes/myvol/_data",
"Destination": "/app",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
}
],
...
"Volumes": {
"/app": {}
},
"WorkingDir": "/app",
"Entrypoint": [
"python",
"main.py"
],
...
the volumes section in your compose - myvol:/app will overwrite the permission and all what it contains in the /app folder , you may delete it from your compose.
if you want to use volumes to presist data , create another mount as /app and point to it in your python code

Resources