Telling Rider to attach docker debugger if project is used by another dockerfile

Hey. Here is my directory structure:

- Project.sln

- SynchronizeSftpUsers (.NET Project)

- .NET Project 2

   - Dockerfile

- .NET Project 3

   - Dockerfile

- SftpServer (atmoz/sftp)

   -  Dockerfile

- docker-compose.yml

 

I have this niche case where I need my SftpServer's user.conf file to be refreshed every minute or so, synchronizing users against other database. Normally, I would need to manually update users.conf file and then restart entire container and I need it to happen in real time without restarts, so I created SynchronizeSftpUsers that updates this file and refreshes the server cache. Of course it could be done better but I'm learning and that's what I have so far.

 

The issue is that my docker compose takes into account .NET Project 2, .NET Project 3 and SftpServer's dockerfiles. I added this docker compose to Rider's configurations and I can successfully debug .NET Project 2 and .NET Project 3. My SftpServer's dockerfile looks like this:

 

# Budujemy aplikację .NET
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-dotnet
WORKDIR /src
COPY ["SynchronizeSftpUsers/SynchronizeSftpUsers.csproj", "SynchronizeSftpUsers/"]
COPY ["SynchronizeSftpUsers/appsettings.json", "SynchronizeSftpUsers/"]
COPY ["Common/", "Common/"]
COPY ["DataAccess/", "DataAccess/"]
RUN dotnet restore "SynchronizeSftpUsers/SynchronizeSftpUsers.csproj"
COPY . .
WORKDIR "/src/SynchronizeSftpUsers"
RUN dotnet build "SynchronizeSftpUsers.csproj" -c Release -o /app/build
RUN dotnet publish "SynchronizeSftpUsers.csproj" -c Release -o /app/publish /p:UseAppHost=false

# Use the latest Ubuntu image
FROM ubuntu:latest

# Update and install necessary packages
RUN apt-get update && \
   apt-get -y install openssh-server cron perl python3 procps wget apt-transport-https ca-certificates && \
   wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
   dpkg -i packages-microsoft-prod.deb && \
   apt-get update && \
   apt-get -y install dotnet-runtime-8.0 aspnetcore-runtime-8.0 && \
   rm -rf /var/lib/apt/lists/* packages-microsoft-prod.deb && \
   mkdir -p /var/run/sshd

# Copy necessary files and scripts
COPY /SftpServer/files/sshd_config /etc/ssh/sshd_config
COPY /SftpServer/files/create-sftp-user /usr/local/bin/
COPY /SftpServer/files/add-new-users /usr/local/bin/
COPY /SftpServer/files/entrypoint /

# Copy the .NET application
COPY --from=build-dotnet /app/publish /app/synchronize-sftp-users
COPY SynchronizeSftpUsers/appsettings.json /app/synchronize-sftp-users/

# Set permissions and configure cron
RUN chmod +x /app/synchronize-sftp-users/SynchronizeSftpUsers.dll

RUN chmod +x /usr/local/bin/add-new-users \
   && chmod +x /usr/local/bin/create-sftp-user \
   && echo -e "#!/bin/bash\n\n\
dotnet /app/synchronize-sftp-users/SynchronizeSftpUsers.dll\n\
/usr/local/bin/add-new-users >> /var/log/addNewUsers.log" > /usr/local/bin/run-jobs \
   && chmod +x /usr/local/bin/run-jobs \
   && echo "*/20 * * * * root /usr/local/bin/run-jobs" >> /etc/crontab

EXPOSE 22

ENTRYPOINT ["/entrypoint"]

This results in SynchronizeSftpUsers running successfully in the background, however I have no idea how can I debug this process inside the container. I don't know how to tell Rider to look for this process inside of this container, because now it's not explicit and it does not work. Can this be done and if not, then how can I do this in a better way?

0
2 comments

Please note that i understand that here there is a cron so it's a bit different becap will launch every now and then, but let's say that I just launch the project once and it runs constantly inside docker, one time.

0

Przemysław Kijak May I know why you need to attach on a process that always been started/stopped? Or I have misunderstood any points?

If you just want to attach Rider debugger in a .NET process running on the container, after Rider 2023.3, use Run | Attach to process, connect to your Docker server, you will see all dotnet processes there. Rider will install remote debugger tools in the container automatically.

0

Please sign in to leave a comment.