starting container process caused: exec: "X": permission denied: unknown - docker

I have this Dockerfile:
# BASE IMAGE
FROM golang:1.19-alpine AS base
ENV GO111MODULE="on" GOOS="linux" CGO_ENABLED=0
RUN apk update \
&& apk add --no-cache \
build-base \
ca-certificates \
curl \
tzdata \
git \
&& update-ca-certificates
# BUILDER IMAGE
FROM base AS builder
WORKDIR /app
COPY . .
RUN go mod download && go mod verify
RUN go build -o producer
# PRODUCTION IMAGE
FROM alpine:latest as prod
WORKDIR /app
COPY ./static ./static
COPY --from=builder /app/producer .
EXPOSE 8080
# RUN chmod +x ./producer
ENTRYPOINT ["/app/producer"]
And when I run it I get this error message:
OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/app/producer": permission denied: unknown
I see a lot of questions and answers related to this problem, but could not make use of them. So please help me ))
I am guessing it is not a permission-related issue as it says, but rather something to do with the way I copy the binary.
Thanks in advance!

Related

Giving execution right to entrypoint script does not working in Dockerfile

I have the following Dockerfile:
# pull official base image
FROM python:3.9.7-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev binutils \
&& apk add --no-cache proj-dev geos gdal
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# copy entrypoint.sh
COPY ./entrypoint.sh .
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh
# copy project
COPY . .
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
Building the image works fine, but when I try a docker run after building the image I get the following error:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/src/app/entrypoint.sh": permission denied: unknown.
ERRO[0000] error waiting for container: context canceled
The line RUN chmod +x /usr/src/app/entrypoint.sh doesn't seem to work because when I comment the ENTRYPOINT statement, build the image then start a containerI can see that the execution right isn't added for that file.
Docker version is:
Docker version 20.10.23, build 7155243
I tried replacing the RUN chmod line with a --chmod=777 option to the COPY of the entrypoint and it didn't change anything.
Any idea why a chmod +x would fail in docker ?
I found a workaround by removing the chmod line and replacing the entrypoint line with the following:
ENTRYPOINT ["/bin/sh", "/usr/src/app/entrypoint.sh"]
This way there is no need for a execution right on the entrypoint script.
But I still don't know why the chmod doesn't work.

upload the ssh folder with keys to docker

I need to throw the ssh folder with the keys in docker.
Dockerfile:
FROM python:3.6-alpine3.12
RUN mkdir /code && mkdir /data
ADD . /code
WORKDIR /code
RUN pip3 install -r requirement && apk add git
RUN mkdir /root/.ssh && -v ~/.ssh:/root/.ssh
RUN apk add -y wget
Error when building:
/bin/sh: illegal option -
The command '/bin/sh -c -v ~/.ssh:/root/.ssh returned a non-zero code: 2
The shell does not recognize the command -v ~/.ssh:/root/.ssh
Try this:
FROM python:3.6-alpine3.12
ADD . /code
WORKDIR /code
RUN pip3 install -r requirement && \
apk add -y git wget && \
mkdir /data
COPY $HOME/.ssh /root/.ssh
PS: I added some Dockerfile's optimization for you
EDIT:
Copying sensitive data into your container is not a good idea unless you really know what you are doing.
If your application needs to connect to a remote server you own it would be better to generate new keys for it specifically and distribute them on your server (public key).

Docker Toolbox not updating changes even after machine remove

Using DockerToolbox, I've been trying for the past few days to update my container to run in heroku.
I cant seem to update the code in the container.
Here are some of things I've tried:
in Docker file change COPY . /app to ADD . /app
Removed docker machine and create a virtualbox
`docker-machine rm default`
`docker-machine create --drive virtualbox default`
build/run docker image
`docker build --no-cache -t appname`
`docker run -it -p 8888:8080 appname`
Also tried docker build --no-cache .
Docker File
FROM python:3.6
# create and set working directory
RUN mkdir /app
WORKDIR /app
# Add current directory code to working directory
ADD . /app/
# set default environment variables
ENV PYTHONUNBUFFERED 1
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV PORT 8080
RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
tar -xvzf ta-lib-0.4.0-src.tar.gz && \
cd ta-lib/ && \
./configure --prefix=/usr && \
make && \
make install
COPY . /app
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install ta-lib
EXPOSE 8080
CMD gunicorn appname.wsgi:application --bind 0.0.0.0:$PORT

Copy a repo clone in dockerfile

I'm trying to clone a repository in my dockerfile and then copy that repository into a specific folder of the docker container.
Here is my dockerfile:
FROM node:11-alpine
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY ./package.json /usr/src/app/
RUN apk --no-cache --virtual build-dependencies add git python make g++ \
&& git config --global url."https://".insteadOf git:// \
&& apk add curl \
&& apk add git bash && git clone https://github.com/vishnubob/wait-for-it.git \
&& yarn install \
&& yarn cache clean --force \
&& apk del build-dependencies
COPY wait-for-it /usr/src/app
This outputs: ERROR: Service 'exchanges_api' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder416734770/wait-for-it: no such file or directory
However, if I add a RUN ls before the copy I get confirmation the file exists, any idea where I might be going wrong?
From this error '' no such file or directory" you see that is the problem with file path and indeed as you can see there is a mistake in this COPY . /package. json this is not a valid path you either need something like .. /package.json or simply package.json depends on where is the file located in your directory.
COPY is used to copy resource from host machine to your docker image. But in you use case, it looks like you are trying to copy resource from one location to other within the docker image.
Replace COPY wait-for-it /usr/src/app with the following:
RUN cp -a wait-for-it /usr/src/app

Docker node js issues: sudo not found

I am having issues with building my docker file with Azure DevOps.
Here is a copy of my docker file:
FROM node:10-alpine
# Create app directory
WORKDIR /usr/src/app
# Copy app
COPY . .
# install packages
RUN apk --no-cache --virtual build-dependencies add \
git \
python \
make \
g++ \
&& sudo npm#latest -g wait-on concurrently truffle \
&& npm install \
&& apk del build-dependencies \
&& truffle compile --all
# Expose the right ports, the commands below are irrelevant when using a docker-compose file.
EXPOSE 3000
CMD ["npm", "run", "server”]
it was working recently now I am getting the following error message:
sudo not found.
What is the cause of this sudo not found error?
Don't use sudo. Just drop that from the command. That image is already running as root by default - there's no reason for it.
TJs-MacBook-Pro:~ tj$ docker run node:10-alpine whoami
root

Resources