I'm trying to execute (RUN) a script but I'm getting a not file found error:
The line is: RUN settings/certs/install-certs.sh
The other lines that use files from the same path don't cause any issues.
What Am I missing here?
Dockerfile:
FROM container-registry.foo.net/maven:3.6.1-alpine as build
WORKDIR /app
COPY . .
RUN chmod +x settings/certs/install-certs.sh
RUN settings/certs/install-certs.sh
RUN mvn clean install -s settings/maven/docker-settings.xml
Output:
Sending build context to Docker daemon 218MB
Step 1/13 : FROM container-registry.foo.net/maven:3.6.1-alpine as build
---> 7445f83cd169
Step 2/13 : WORKDIR /app
---> Using cache
---> b08dcd4a3395
Step 3/13 : COPY . .
---> Using cache
---> c843717f9c58
Step 4/13 : RUN chmod +x settings/certs/install-certs.sh
---> Using cache
---> 17c6546c749b
Step 5/13 : RUN settings/certs/install-certs.sh
---> Running in 106d58b6bb25
/bin/sh: settings/certs/install-certs.sh: not found
The command '/bin/sh -c settings/certs/install-certs.sh' returned a non-zero code: 127
It turn out the line separator was the reason of the failure, replacing CRLF to LF did the trick.
Hard to identify when the error says "file not found".
Related
When I run
docker build -f docker/webpack.docker services/webpack --build-arg env=production
twice in a row, Docker builds my image each time, starting from the first RUN (the COPY uses the cache).
FROM node:lts
ARG env=production
ENV NODE_ENV=$env
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production=false --non-interactive
COPY . .
RUN node --max-old-space-size=20000 node_modules/.bin/svg2fonts icons -o assets/markons -b mrkn -f markons -n Markons
RUN node --max-old-space-size=20000 node_modules/.bin/webpack --progress
How can I get it to cache those RUNs?
Output looks like:
Sending build context to Docker daemon 3.37MB
Step 1/9 : FROM node:lts
---> 0c601cba9f11
Step 2/9 : ARG env=production
---> Using cache
---> dd38b2167c75
Step 3/9 : ENV NODE_ENV=$env
---> Using cache
---> 800f5afd416c
Step 4/9 : WORKDIR /app
---> Using cache
---> d15b93dce11d
Step 5/9 : COPY package.json yarn.lock ./
---> Using cache
---> a049dd1609a8
Step 6/9 : RUN yarn install --frozen-lockfile --production=false --non-interactive
---> Using cache
---> d5e51b0d556c
Step 7/9 : COPY . .
---> 92990e326d4b
Step 8/9 : RUN node --max-old-space-size=20000 node_modules/.bin/svg2fonts icons -o assets/markons -b mrkn -f markons -n Markons
---> Running in a23878db7b0e
Wrote assets/markons/markons.css
Wrote assets/markons/markons.js
Wrote assets/markons/markons.html
Wrote assets/markons/markons-chars.json
Wrote assets/markons/markons.svg
Wrote assets/markons/markons.ttf
Wrote assets/markons/markons.woff
Wrote assets/markons/markons.woff2
Wrote assets/markons/markons.eot
Removing intermediate container a23878db7b0e
---> 3bce79d0ecf0
Step 9/9 : RUN node --max-old-space-size=20000 node_modules/.bin/webpack --progress
---> Running in b6d460488950
<s> [webpack.Progress] 0% compiling
...
See the description:
If the contents of all external files on the first COPY command are
the same, the layer cache will be used and all subsequent commands
until the next ADD or COPY command will use the layer cache.
However, if the contents of one or more external files are different,
then all subsequent commands will be executed without using the layer
cache.
So every time the content is changed two last RUN will be executed with no cache. There is no way to control caching yet. Maybe it's a better option to specify volumes?
I have been trying to make a Dockerfile, that would let me build my go server as binary and then run it either from the scratch image or alpine. The server works fine locally, on macOS 10.13.5, and I made it work when it wasn't from binary on Docker.
I keep getting this error:
standard_init_linux.go:190: exec user process caused "exec format error"
I have been googling around and found something about system architecture. I am not sure how to check if that is the error and/or how to fix it.
Any hints for debugging or possible fix are much appreciated.
My Dockerfile:
FROM golang:1.10.3 as builder
WORKDIR /go/src/gitlab.com/main/server
COPY . .
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -a -o main .
FROM scratch
ADD main /
CMD ["/main"]
The output:
Building go
Step 1/9 : FROM golang:1.10.3 as builder
---> 4e611157870f
Step 2/9 : WORKDIR /go/src/gitlab.com/main/server
Removing intermediate container 20cd4d66008b
---> 621d9fc02dde
Step 3/9 : COPY . .
---> cab639571baf
Step 4/9 : RUN go get -d -v ./...
---> Running in 7681f9adc7b2
Removing intermediate container 7681f9adc7b2
---> 767a4c9dfb94
Step 5/9 : RUN go build -a -installsuffix cgo -o main .
---> Running in a6ec73121163
Removing intermediate container a6ec73121163
---> b9d7d1c0d2f9
Step 6/9 : FROM alpine:latest
---> 11cd0b38bc3c
Step 7/9 : WORKDIR /app
---> Using cache
---> 6d321d334b8f
Step 8/9 : COPY . .
---> 048a59fcdd8f
Step 9/9 : CMD ["/app/main"]
---> Running in d50d174644ff
Removing intermediate container d50d174644ff
---> 68f8f3c6cdf7
Successfully built 68f8f3c6cdf7
Successfully tagged main_go:latest
Creating go ... done
Attaching to go
go | standard_init_linux.go:190: exec user process caused "exec format error"
go exited with code 1
As #tgogos pointed out did I need to use what I build in the first step.
My final Dockerfile ended like this with a few further improvements: The important part is second last line though:
FROM golang:1.10.3 AS build
WORKDIR /go/src/gitlab.com/main/server
COPY . .
RUN go get github.com/golang/dep/cmd/dep && \
dep ensure && \
rm -f schema/bindata.go && \
go generate ./schema
RUN CGO_ENABLED=0 GOOS=linux go build -a -o main .
FROM alpine
RUN apk add --no-cache ca-certificates
COPY --from=build /go/src/gitlab.com/main/server/main .
CMD ["/main"]
Server Version: 18.03.1-ce ,RHEL 7.2 .Here is my dockerfile:
FROM openjdk:8-jdk-alpine
ENV http_proxy http://192.168.156.25:3128
ENV https_proxy http://192.168.156.25:3128
RUN apk update && apk upgrade && apk add netcat-openbsd
RUN mkdir -p /usr/local/licensingservice
ADD #project.build.finalName#.jar /usr/local/licensingservice/
ADD run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh
it build without error:
---> Using cache
---> 8fa60876c229
Step 5/9 : RUN mkdir -p /usr/local/licensingservice
---> Using cache
---> bca46b1256e1
Step 6/9 : ADD licensing-service-0.0.1-SNAPSHOT.jar /usr/local/licensingservice/
---> a66979ed3755
Step 7/9 : ADD run.sh ./run.sh
---> 95b492565374
Step 8/9 : RUN chmod +x run.sh
---> Running in eec3075c30f3
Removing intermediate container eec3075c30f3
---> 96a2d7b89b80
Step 9/9 : CMD ./run.sh
---> Running in c338e9d33371
Removing intermediate container c338e9d33371
---> 324d5a83cf84
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 324d5a83cf84
Successfully tagged johncarnell/tmx-licensing-service:chapter4
but docker run -it 324d5a83cf84:
/bin/sh: ./run.sh: not found
I debug using docker run --rm -it 324d5a83cf84 cat ./run.sh,it print the file well.
run.sh:
#!/bin/sh
echo "hello1"
I suspect you are working on Windows and you are using the default Windows newline: CR LF. Change to LF in your run.sh and it will work like a charm.
But how to do that you ask? Open run.sh in Notepad++ and look at the bottom right of the window. Click on Windows (CR LF) and select Unix (LF).
I have written a multistage build dockerfile trying to follow https://docs.docker.com/engine/userguide/eng-image/multistage-build/ :
FROM gcc:latest as compiler
WORKDIR /compiling/
ADD hello.c .
RUN gcc ./hello.c -o .hello
FROM scratch
WORKDIR /running/
COPY --from=compiler /compiling/hello .
CMD ["./hello"]
I expect that it builds an executable in a /compiling directory, copies it to /running directory and runs it there. However, I get this output:
C:\hellonode3>docker build -t hello-node3:v6 .
Sending build context to Docker daemon 4.608kB
Step 1/8 : FROM gcc:latest as compiler
---> 81ffb25b1dec
Step 2/8 : WORKDIR /compiling/
---> Using cache
---> 2337f71a826d
Step 3/8 : ADD hello.c .
---> Using cache
---> aaef6bd8d2ff
Step 4/8 : RUN gcc ./hello.c -o .hello
---> Using cache
---> 665f96147ec3
Step 5/8 : FROM scratch
--->
Step 6/8 : WORKDIR /running/
---> Using cache
---> 84f8d58a56a1
Step 7/8 : COPY --from=compiler /compiling/hello .
COPY failed: stat /var/lib/docker/overlay2/4fd98195ec5ffdb392e2d5d64c8f9acdde56c1c1e517cd9076ee9fd59ab2c4dc/merged/compiling/hello: no such file or directory
I do not exactly know why this happens. Can you explain? How can it be fixed?
Just a stupid typo!
There should be a line
RUN gcc ./hello.c -o ./hello
instead.
Docker is not able to find glide, which was installed successfully in steps 3 and 4 (below). I ran
docker build .
This is the first part of the Dockerfile:
FROM golang:latest as builder
# Set up workdir
WORKDIR /go/src/github.com/cayleygraph/cayley
# Restore vendored dependencies
RUN sh -c "curl https://glide.sh/get | sh"
COPY glide.* ./
RUN glide install
But it failed on step 5 with this error:
docker build .
Sending build context to Docker daemon 65.18MB
Step 1/29 : FROM golang:latest as builder
---> 1a34fad76b34
Step 2/29 : WORKDIR /go/src/github.com/cayleygraph/cayley
---> Using cache
---> dd9a295edeed
Step 3/29 : RUN sh -c "curl https://glide.sh/get | sh"
---> Using cache
---> b432efdb0630
Step 4/29 : COPY glide.* ./
---> Using cache
---> 936b9f7837eb
Step 5/29 : RUN glide install
---> Running in b244dcff6576
/bin/sh: 1: glide: not found
The command '/bin/sh -c glide install' returned a non-zero code: 127
Installing glide worked, not sure why it's not finding the actual executable though. Any ideas?
Make glide executable as well, in the Dockerfile. And skip the / in your COPY statement. Try to add this before you try to run it.
RUN chmod +x <file>
Seems like the install process only download the executable