dockerfile cant find entrypoint.sh - docker

My filesystem:
Dockerfile
entrypoint.sh
package.json
/shared_volume/
Dockerfile
FROM node:8
# Create and define the node_modules's cache directory.
RUN mkdir /usr/src/cache
WORKDIR /usr/src/cache
COPY . .
RUN npm install
# Create and define the application's working directory.
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
# entrypoint to copy the node_modules and root files into /usr/src/app, to be shared with my local volume.
ENTRYPOINT ["/usr/src/cache/entrypoint.sh"]
package.json
{
"name": "test1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "echo hello world start"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"rimraf": "^3.0.1"
}
}
entrypoint.sh
#!/bin/bash
cp -r /usr/src/cache/. /usr/src/app/.
command line - bash script
If I run this code (note: using windows 10 with cmder, hence %cd% not pwd):
docker run -it --rm -v %cd%/shared_volume:/app --privileged shared-volume-example bash
Error
standard_init_linux.go:211: exec user process caused "no such file or directory"
If I take out the reference to entrypoint, then the code works, so what is going on with the entrypoint?
Any suggestions.
thanks

ok someone else posted an answer regarding line endings. I used atom line-ending-selector and set it to LF in replacement, and resaved the file and now it works.

Related

Docker container is running json-server but browser says page isn't working

Here is my dockerfile
FROM node:16.18.1-alpine
WORKDIR /app
COPY package.json /app
RUN npm install
EXPOSE 3000
COPY . /app
ENTRYPOINT \["npm", "start"\]
and in my package.json here is the start script
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "json-server --watch db.json"
},
and here is a screenshot of docker logs
Docker logs screenshot
browser screenshot running at localhost:3000
Browser running at localhost:3000
It should serve my db.json file with this data
{
"currency" : \[
{
"id": 1,
"rate": 117,
"value": "usd",
"currency": "USD",
"selected": true
}
\]
}
I changed some few things in the docker file and it worked.
FROM node:16.18.1-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json /app
RUN npm install -g json-server
COPY . /app
CMD json-server --watch /app/db.json --port 3000 --host 0.0.0.0

Debugging with 'Docker .NET Core Attach' not working anymore

I have several ASP.NET Core (6.0) WebApi projects that are dockerized using docker-compose. For local development, I use a docker-compose file which references Dockerfiles that build / publish the projects in Debug mode. Then in order to debug, I use the 'Docker .NET Core Attach (Preview)' launch configuration and select the corresponding docker container, which then prompts me about copying the .NET Core debugger into the container.
Until recently, this always worked and I could debug inside the container. Now suddenly, after being prompted and trying to copy the debugger into the container, I always get the following error:
Starting: "docker" exec -i web_roomservice /remote_debugger/vsdbg
--interpreter=vscode
Error from pipe program 'docker': FATAL ERROR: Failed to initialize dispatcher with error 80131534
The pipe program 'docker' exited unexpectedly with code 255.
I tried re-installing the Docker Engine + docker-compose (with the latest version), re-installing VS Code + the 'Docker' and 'C#' extensions, migrating from ASP.NET Core 5.0 to 6.0 (since 5.0 is not supported anymore) and obviously rebuilding my images multiple times, but nothing seems to work and I can't find anything online. Any help with this would be greatly appreciated, since as of now I can't debug which sucks.
These are my docker-compose, Debug-Dockerfile and launch config (for one project / service):
version: "3.7"
services:
roomservice:
image: web_roomservice
container_name: web_roomservice
build:
context: ./
dockerfile: Dockerfile.RoomService.Debug
expose:
- "5011"
volumes:
- /etc/localtime:/etc/localtime:ro
environment:
- ASPNETCORE_ENVIRONMENT=Development
user: "root:root"
logging:
driver: "json-file"
options:
max-size: "5m"
(There's more but I only included the section with this one service)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
#EXPOSE 5011
ENV ASPNETCORE_URLS=http://+:5011
# Install netpbm which is used for .pgm to .png file conversion for map images
RUN apt-get -y update --silent
RUN apt-get -y install netpbm --silent
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RoomService/RoomService.csproj", "./RoomService/"]
COPY ["EventBusRabbitMQ/EventBusRabbitMQ.csproj", "./EventBusRabbitMQ/"]
COPY ["Common/Common.csproj", "./Common/"]
RUN dotnet restore "RoomService/RoomService.csproj"
COPY RoomService ./RoomService
COPY EventBusRabbitMQ ./EventBusRabbitMQ
COPY Common ./Common
WORKDIR "/src/RoomService"
RUN dotnet build "RoomService.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish "RoomService.csproj" -c Debug -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RoomService.dll"]
(This Dockerfile is placed in the workspace folder (parent of the actual RoomService project folder) in order to include the Common project)
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker .NET Core Attach (Preview)",
"type": "docker",
"request": "attach",
"platform": "netCore",
"sourceFileMap": {
"/src/RoomService": "${workspaceFolder}"
}
}
]
}
(This launch configuration is placed in the actual RoomService project folder's .vscode subfolder)
Had the same problem today. Try deleting the ~/vsdbg directory, if you are on MacOS.
David is right. I was having the same issue. I am running WSL2 (Ubuntu) and when I deleted the ~/.vsdbg directory that fixed the issue for me.
This configuration below works perfectly in .NET6.
content of .vscode/launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "your-container-name" ],
"debuggerPath": "/root/vsdbg/vsdbg",
"quoteArgs": false
},
"sourceFileMap": {
"path/in/container": "${workspaceRoot}/local/path"
}
}
]
}
I have also installed dotnet debugger in my Dockerfile as follow:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS base
...
FROM base AS debug
RUN apt-get update
RUN apt-get install -y procps
RUN apt-get install -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg
...
Full instruction is covered in this YouTube tutorial: Debugging .NET Core in Docker with VSCode

Vue Vite cannot connect to docker container

Hi I have install fresh app vue3 typescript + vite , my problem after building the image and spin the container. I cannot access the localhost:3000, the browser will just display
The connection was reset
docker run --rm -it -v %cd%/:/app/src -p 3000:3000 myvitets
Dockerfile
FROM node:14-buster-slim
# make the 'app' folder the current working directory
WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "dev"]
I also add .dockerignore
node_modules/
.git
.gitignore
can someone help me please how to run my app to the container..
Thank you in advance.
I had the same problem and the below works for me.
In package.json, change the scripts
From
"dev": "vite"
To
"dev": "vite --host 0.0.0.0"
First: in the package.json add --host tag
"scripts": {
"dev": "vite --host",
"build": "vite build",
"preview": "vite preview --port 4173",
"test:unit": "vitest --environment jsdom"
},
Second: in the vite.config.js add the server port
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 3000
},
plugins: [vue()],
resolve: {
alias: {
'#': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
the port should be the same as in the Dockerfile, in your case 3000

Debugging docker image in VS code : cs file cannot be found:

I am trying to debug a docker image using the given description in this article.
I have created a Dockerfile like this :
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
RUN apt update && \
apt install procps -y && \
apt install unzip && \
curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l /vsdbg
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY *.sln ./
COPY server/Business/NotificationModule.Business.csproj server/Business/
COPY server/Common/NotificationModule.Common.csproj server/Common/
COPY server/Data/NotificationModule.Data.csproj server/Data/
COPY server/DomainModel/NotificationModule.DomainModel.csproj server/DomainModel/
COPY server/Host/NotificationModule.Host.csproj server/Host/
RUN dotnet restore
COPY . .
WORKDIR "/src/server/Host/"
RUN dotnet build "NotificationModule.Host.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish "NotificationModule.Host.csproj" -c Debug -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NotificationModule.dll"]
and I have added the entry for debugging docker images in launch.json like this :
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "objective_torvalds" ],
"debuggerPath": "/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
}
},
It seems that it is working and I can attach the debugger to my process but the problem is that when the debugger hits a breakpoint it can not find any cs files and shows an empty cs file instead.
I would like to ask if you know what I have done wrong.
UPDATE :
I have noticed that the debugger is looking for my cs files under src folder which apparantly doens't exist neither in my working directory nor in the image itself . So the question is why it is looking there.
OK I've got it . That was my mistake because I was using the same docker file that we have for production to copy pdb files into the docker image and those pdb files have been built on a docker container in a src directory so it was looking there .
I just copied the files from my bin/debug into the docker image and now it is workng perfectly.( and later I noticed that it was also mentioned in the article).
so here is the new DockerFile :
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
RUN apt update && \
apt install procps -y && \
apt install unzip && \
curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l /vsdbg
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY bin/debug .
ENTRYPOINT ["dotnet", "NotificationModule.dll"]
and BTW you shouldn't add bin into your .dockerignore file
I had the same problem - debugger worked (I could see variables values), but the debugger couldn't find my .cs files:
It turned out that the default value of sourceFileMap in launch.json was incorrect, I found information how to use it properly at OmniSharp Github.
Here's how to fix the issue:
After I clicked Create File button in the popup with the error I was able to check where the debugger was looking for the source file. In my case the error message was:
Unable to write file '/out/src/MyApp/WebDriverFactory/WebDriverFactory.cs' (Unknown (FileSystemError): Error: EROFS: read-only file system, mkdir '/out')
I could use the message above to use fix my paths in sourceFileMap:
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker .NET Core Attach (Preview)",
"type": "docker",
"request": "attach",
"platform": "netCore",
"sourceFileMap": {
"/out/src/": "${workspaceFolder}/src"
}
}
]
}
I used .NET 6 with Alpine images:
mcr.microsoft.com/dotnet/runtime:6.0-alpine3.14-amd64

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