/bin/bash behavior in container shell and dockerfile - docker

I'm new to dockerfile and I have a hard time running a simple check command present in an image.
When I run a container with this image, I'm seeing this behavior from the shell (/bin/sh):
$ /bin/bash -c foamVersion
/bin/bash: foamVersion: command not found
$ /bin/bash
nextfoam#3ab61c950023:/home$ foamVersion
OpenFOAM-6
I'm running it from /bin/sh because this image seems to use it by default (Ubuntu 18).
My goal is to do get foamVersion result. Here's the dockerfile:
FROM nextfoam/baram6:latest
SHELL ["/bin/bash", "-c"]
RUN foamVersion
On host (Ubuntu 21.10), I run:
docker build -t mybaram:latest .
[+] Building 0.3s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 384B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/nextfoam/baram6:latest 0.0s
=> CACHED [1/2] FROM docker.io/nextfoam/baram6:latest 0.0s
=> ERROR [2/2] RUN foamVersion 0.3s
------
> [2/2] RUN foamVersion:
#5 0.242 /bin/bash: foamVersion: command not found
type foamVersion
foamVersion is a function
foamVersion ()
{
if [ "$1" ]; then
foamInstDir=$FOAM_INST_DIR;
. $WM_PROJECT_DIR/etc/config.sh/unset;
. $foamInstDir/OpenFOAM-$1/etc/bashrc;
cd $WM_PROJECT_DIR;
echo "Changed to OpenFOAM-$1" 1>&2;
else
echo "OpenFOAM-$WM_PROJECT_VERSION" 1>&2;
fi
}
Any idea how to get foamVersion working from build process in dockerfile?

Related

runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory

Hi I am creating an image on docker and below are the commands on Dockerfile
FROM node
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 80
CMD ["node", "server.js"]
When I run the command Docker build . it gives below response
[+] Building 2.0s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 138B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 1.0s
=> [internal] load build context 0.0s
=> => transferring context: 295B 0.0s
=> [1/4] FROM docker.io/library/node#sha256:eee19816ad7ae65dbcac037629c355fa4b369d163a660bc9718df8f945e79eeb 0.0s
=> CACHED [2/4] WORKDIR /app 0.0s
=> CACHED [3/4] COPY . /app 0.0s
=> ERROR [4/4] RUN npm install 0.7s
------
** > [4/4] RUN npm install:
#8 0.673 runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory**
Can some please guide
I was expecting the image to be built.
I was facing the same problem in a CI/CD context and it was related to the /var/lib/docker directory.
So you can try these steps (doing so you will temporary loose all your Docker layers and images in your host but can revert the operation if not ok)
Stop your docker service
sudo mv /var/lib/docker /var/lib/_docker
restart the Docker service (if needed, sudo mkdir /var/lib/docker)

create minimalistic image - exec: no such file or directory [duplicate]

This question already has answers here:
Docker: standard_init_linux.go:211: exec user process caused "no such file or directory"
(2 answers)
Closed 24 days ago.
I'm learning Docker and I'm trying to create the most simple and light image as possible. That's what I did.
helloworld directory:
$ ls
Dockerfile helloworld.c
helloworld.c
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
Dockerfile
FROM scratch
COPY helloworld /
CMD ["/helloworld"]
I compiled the .c file:
$ gcc -o helloworld helloworld.c
$ ./helloworld
Hello world!
Then I created the image:
$ docker build --tag helloworld .
[+] Building 0.2s (5/5) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 93B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 33B 0.0s
=> CACHED [1/1] COPY helloworld / 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:c5664c4c93727aae40daca2c1fc0aa13ea2e2c58ba2962fa8d981aa0ec09012e 0.0s
=> => naming to docker.io/library/helloworld
Then when I run the container I get the error exec /helloworld: no such file or directory:
$ docker run helloworld
exec /helloworld: no such file or directory
What am I doing wrong? Should I compiled the helloworld in a different mode?
You need to compile at docker build time, e.g.:
FROM ubuntu
RUN apt-get update -y && apt-get install gcc -y
COPY helloworld.c .
RUN gcc -o helloworld helloworld.c
ENTRYPOINT ["./helloworld"]
$ docker build -t helloworld .
$ docker run helloworld
Hello world!

In Dockerfile build how to get container with ssh keys loaded in

I have docker image which already have keys saved.I want to get docker container which will have ssh keys loaded when i run it. I went over few stackoverflow questions where its suggested to use as below which didnt help
RUN eval $(ssh-agent -s) && ssh-add /root/.ssh/ok
My Dockerfile look like
FROM cmf
RUN eval $(ssh-agent -s) && ssh-add /root/.ssh/ok
when i created docker image and ran it like , i dont see keys loaded
docker run -it intro_to_docker2 /bin/bash
root#17a094f42efb:/# ssh-add -l
Could not open a connection to your authentication agent.
root#17a094f42efb:/#
Below is build
% docker build --no-cache -t intro_to_docker2 .
[+] Building 0.3s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 102B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/cmf:latest 0.0s
=> CACHED [1/2] FROM docker.io/library/cmf 0.0s
=> [2/2] RUN eval $(ssh-agent -s) && ssh-add /root/.ssh/ok 0.2s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:4acb58d65b43a15e6a85a99f99d223d87c90736eed07d427e8ceaeac544f87a4 0.0s
=> => naming to docker.io/library/intro_to_docker2

How do you get a directory listing to output during build in Docker 20.10.3? (March 2022) [duplicate]

This question already has answers here:
Why is docker build not showing any output from commands?
(6 answers)
Closed 11 months ago.
The answers here don't seem to work. The answer here also doesn't work. I suspect something has changed about Docker's build engine since then.
My Dockerfile:
FROM node:16.14.2-alpine
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY dist .
EXPOSE $SEEDSERV_PORT
RUN pwd
RUN echo "output"
RUN ls -alh
RUN contents="$(ls -1 /usr/src/app)" && echo $contents
# CMD ["node","server.js"]
ENTRYPOINT ["tail", "-f", "/dev/null"]
Which gives this output from build:
✗ docker build --progress auto --build-arg SEEDSERV_PORT=9999 -f build/api/Dockerfile .
[+] Building 2.1s (14/14) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:16.14.2-alpine 1.9s
=> [internal] load build context 0.0s
=> => transferring context: 122B 0.0s
=> [1/9] FROM docker.io/library/node:16.14.2-alpine#sha256:da7ef512955c906b6fa84a02295a56d0172b2eb57e09286ec7abc02cfbb4c726 0.0s
=> CACHED [2/9] WORKDIR /usr/src/app 0.0s
=> CACHED [3/9] COPY package.json yarn.lock ./ 0.0s
=> CACHED [4/9] RUN yarn 0.0s
=> CACHED [5/9] COPY dist . 0.0s
=> CACHED [6/9] RUN pwd 0.0s
=> CACHED [7/9] RUN echo "output" 0.0s
=> CACHED [8/9] RUN ls -alh 0.0s
=> CACHED [9/9] RUN contents="$(ls -1 /usr/src/app)" && echo $contents 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:d1dd7ac452ecacc803eed2bb1deff654c3296a5576b6f418dbd07c5f2e644f1a 0.0s
Adding --progress plain gives slightly different output but not what I'm looking for, e.g.:
#11 [7/9] RUN echo "output"
#11 sha256:634e07d201926b0f70289515fcf4a7303cac3658aeddebfa9552fc3054ed4ace
#11 CACHED
How can I get a directory listing during build in 20.10.3? I can exec into the running container but that's a lot more work.
If your build is cached, there's no output from the run to show. You need to include --no-cache to run the command again for any output to display, and also include --progress plain to output to the console.

How do I get the latest version of file in GitHub Release and download the file in Dockerfile?

I'm trying to get the version number of the latest release of a Github. (Stored in the LATEST_VERSION argument). Using this, I want to download a particular file from a GitHub repository (Using the ADD) command, however I am getting an error Error Image Screenshot
FROM adoptopenjdk/openjdk11:jdk-11.0.6_10-alpine
RUN mkdir -p /home/app
ARG ORG_NAME=archu0212
ARG REPO_NAME=Test
ARG LATEST_VERSION=$(curl -s https://api.github.com/repos/${ORG_NAME}/${REPO_NAME}/releases/latest | grep "tag_name" | cut -d'v' -f2 | cut -d'"' -f1)
ADD https://github.com/${ORG_NAME}/${REPO_NAME}/releases/download/v${LATEST_VERSION}/MainTestFile.jar /home/app
ENTRYPOINT ["java", "-jar", "/home/app"]
docker build -t test-image .
Building 2.0s (6/7)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 649B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/adoptopenjdk/openjdk11:jdk-11.0.6_10-alpine 1.4s
=> [1/3] FROM docker.io/adoptopenjdk/openjdk11:jdk-11.0.6_10-alpine#sha256:a4e96cebf2f00b354b6f935560d4e64ad24435af77322cdf538975962d7e17d3 0.0s
=> ERROR https://github.com/archu0212/Test/releases/download/v$(curl/MainTestFile.jar 0.3s
=> CACHED [2/3] RUN mkdir -p /home/app 0.0s
------
> https://github.com/archu0212/Test/releases/download/v$(curl/MainTestFile.jar:
Any help would be appreciated. Stuck on this for a week.

Resources