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
Related
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".
Good day everyone. I'm in the middle of a task using our docker image to build go microservice. To reduce build time, keep the images under control.
I expect that after downloading the golang image from the docker hub, upload it to our registry and use it in all the dockerfiles of our microservices.
As soon as I started building go mircoservice, during the installation phase go gave me an error:
11:04:16 [91m / bin / sh: go: not found
11:04:16 [0mThe command '/ bin / sh -c go install -mod vendor' returned a non-zero code: 127
I tried to install go in a container, write $ PATH for go, but nothing helped. Then I was told that this image already contains go.
Here are the complete build steps:
11:04:15 Step 1/7 : FROM 192.168.0.8:5000/golang
11:04:15 ---> 49f356fa4513
11:04:15 Step 2/7 : EXPOSE 80
11:04:15 ---> Using cache
11:04:15 ---> 6e0c49e600e6
11:04:15 Step 3/7 : WORKDIR /go/src/autocomplete-trains
11:04:15 ---> Using cache
11:04:15 ---> 41cccfb1ed82
11:04:15 Step 4/7 : COPY . .
11:04:15 ---> 1a44653382a8
11:04:15 Step 5/7 : RUN chmod +x ./start.sh
11:04:15 ---> Running in c13b5cfbfd0b
11:04:16 Removing intermediate container c13b5cfbfd0b
11:04:16 ---> ab03d13e5984
11:04:16 Step 6/7 : RUN go install -mod vendor
11:04:16 ---> Running in b3727493f938
11:04:16 [91m/bin/sh: go: not found
11:04:16 [0mThe command '/bin/sh -c go install -mod vendor' returned a non-zero code: 127
11:04:17 Build step 'Execute shell' marked build as failure
Dockerfile:
FROM 192.168.0.8:5000/golang
EXPOSE 80
WORKDIR /go/src/autocomplete-trains
COPY . .
RUN chmod +x ./start.sh
RUN go install -mod vendor
ENTRYPOINT ./script.sh
Note: If FROM 192.168.0.8:5000/golang:1.15.5-alpine is changed to FROM golang then everything works (but we don't wish to rely upon dockerhub so this is not a viable solution).
The process used to push the image into our repository was:
sudo docker pull golang
sudo docker tag golang:latest 192.168.0.8:5000/golang:1.15.5-alpine
sudo docker push 192.168.0.8:5000/golang:1.15.5-alpine
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"]
I thought i understand Docker already, but today i found some problem about utilizing docker cache.
Here is my dockerfile
FROM quay.io/my_company/phpjenkins
WORKDIR /usr/src/my_project
ADD composer.json composer.json
ADD composer.lock composer.lock
RUN composer install -o
ADD . .
RUN mkdir -p temp/unittest/cache log
RUN cp app/config/config.unittest.template.neon app/config/config.unittest.neon
CMD ["tail", "-f", "/dev/null"]
I expect docker to use the cache until ADD . .
However, every build, look like docker try to do composer install every time.
Here is some output
+ docker-compose -f docker-compose.yml run app vendor/bin/phpunit -d memory_limit=2048M
Creating network "xxx_default" with the default driver
Creating xxx_rabbitmq_1
Creating xxx_mysql_1
Building app
Step 1/9 : FROM quay.io/my_company/phpjenkins
---> f10ea65fb7df
Step 2/9 : WORKDIR /usr/src/my_project
---> Using cache
---> 07ad76770cd2
Step 3/9 : ADD composer.json composer.json
---> Using cache
---> 0d22314b81af
Step 4/9 : ADD composer.lock composer.lock
---> Using cache
---> 3d41825efcb3
Step 5/9 : RUN composer install -o
---> Running in 38de5f08eb46
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/local/bin/composer self-update" to get the latest version.
Do not run Composer as root/super user! See https://getcomposer.org/root for details ....
...
---> aa05dc9ddc5f
Removing intermediate container 581aa7e4b00f
Step 6/9 : ADD . .
---> 8796a9235b9a
Removing intermediate container b7354231fbd7
I run out of lead, what could be possible thing that dockerfile didn't use cache for RUN composer install command
I'm using Docker version 17.05.0-ce, build 89658be on Debian, if this help for investigation.
Please advise.
As a work-around you could create two Dockerfiles. One that creates an image at the point where you would like to cache. The second Dockerfile can then use the first image as its base and make modifications as required.
FROM quay.io/my_company/phpjenkins
WORKDIR /usr/src/my_project
ADD composer.json composer.json
ADD composer.lock composer.lock
RUN composer install -o
CMD ["tail", "-f", "/dev/null"]
Build this file to mycomposerimage using
docker build -t mycomposerimage .
Then second dockerfile picks up from there
FROM mycomposerimage
WORKDIR /usr/src/my_project
ADD . .
RUN mkdir -p temp/unittest/cache log
RUN cp app/config/config.unittest.template.neon app/config/config.unittest.neon
CMD ["tail", "-f", "/dev/null"]