ERROR: Service 'api-gateway' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder931060141/api-gateway: no such file or directory - docker

I am having trouble building a Go-based Docker project. My overall directory structure looks like:
api-gateway
│ ├─handler
│ └─resource
--Dockerfile
My Dockerfile contains:
FROM alpine:3.2
ADD api-gateway /api-gateway
ADD resource/pri_key.pem resource/pub_key.pem /resource/
#ADD resource/ca-certificates.crt /etc/ssl/certs/
VOLUME /resource/
ENTRYPOINT [ "/api-gateway" ]
Even though I'm using ADD to include a file in the image, I'm still getting an error. api-gateway is a directory that includes the Dockerfile inside.
D:\FileWithDocument\ExtraCodeProject\shop-micro-master>docker-compose up
Building api-gateway
Step 1/5 : FROM alpine:3.2
---> 98f5f2d17bd1
Step 2/5 : ADD api-gateway /api-gateway
ERROR: Service 'api-gateway' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder931060141/api-gateway: no such file or directory
I use Docker Desktop in Windows.
Docker Engine version is:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: true
When i download the github project and run docker build, it still outputs this error.
ERROR: Service 'api-gateway' failed to build: ADD failed: stat /var/lib/docker/tmp/docker-builder931060141/api-gateway: no such file or directory

When you run docker build, the directory you give it becomes the context directory; you can only refer to file paths within that directory tree, and any file paths in COPY or ADD statements are always relative to that directory. That means if you're running docker build from the directory named api-gateway that contains the Dockerfile, . is the same directory. Your Dockerfile might look more like:
FROM alpine:3.2
# This will create the directory in the image if it
# doesn't already exist.
WORKDIR /api-gateway
# Copy the entire current directory into the image.
# (Prefer COPY to ADD, unless you specifically want
# automatic archive extraction or HTTP fetches.)
COPY . .
# Copy in some additional files.
# (Remember that anyone who has the image can extract any
# file from it: this leaks a private key.)
COPY resource/pri_key.pem resource/pub_key.pem /resource/
COPY resource/ca-certificates.crt /etc/ssl/certs/
# Set the default command to launch.
# (Prefer CMD to ENTRYPOINT: it is easier to get a debugging
# container with a shell, and there is a useful pattern that
# uses an ENTRYPOINT wrapper to do first-time setup before
# launching the CMD.)
CMD ["/api-gateway/handler"]
If you see a "docker-builder12345678/...: no such file or directory" error, you should always interpret the path components after the long number as relative to the directory you passed to docker build.

Related

How to do the hello_world example from GitHub:linuxkit/linuxkit?

Situation and Problem
I am trying to follow this guide on "how to make your own linuxkit with docker for mac", where you can add some kernel modules usually not present in docker images.
After a lot of reading and testing I am failing to do the simplest (one would think) test case in the repository:
linuxkit/test/cases/020_kernel/011_kmod_4.9.x/
https://github.com/linuxkit/linuxkit/tree/master/test/cases/020_kernel/011_kmod_4.9.x
checking the container for the linux kernel-version and config:
... host$ docker run -it --rm -v /:/host -v $(pwd):/macos alpine:latest
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
bdf0201b3a05: Pull complete
Digest: sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913
Status: Downloaded newer image for alpine:latest
/ # / # uname -a
/bin/sh: /: Permission denied
/ #
/ #
/ # uname -a
Linux 029b8e5ada75 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 Linux
/ # cp /host/proc/config.gz /macos/
/ # exit
I went back in the github history to find the hash for my local linuxkit kernel version and modified the dockerfile of that example (or basically used the old one).
So far so good. The problem is, that if I try to do anything related to kernel modules (modinfo, modprobe, depmod, insmod), I will get errors like these:
modinfo: can't open '/lib/modules/4.9.125-linuxkit/modules.dep': No such file or directory
This is because that path simply does not exist in the container (there is not even a modules folder). That is also true if I were to check -- as above -- just in alpine:latest. So there doesn't seem to happen any magic in that dockerfile.
Question
Now I am completely puzzled and left stranded on what to do, hence my question ...
How to do the hello_world example from linuxkit/linuxkit ?
additional notes
The docs of the linuxkit-repository do not mention anything about that problem:
https://github.com/linuxkit/linuxkit/blob/master/docs/kernels.md#compiling-external-kernel-modules
For easy testing I am using
docker-compose
# build with
# docker-compose build
version: '3'
services:
linux-builder:
image: my_linux_kit
build:
context: .
dockerfile: my_linux_kit.dockerfile
# args:
# buildno: 1
privileged: true
And I even tricked it (by inserting by hand) into not showing any errors, but also not doing what I suppose the code should do:
... host$: docker exec -it 7a33fad37914 sh
/ # ls
bin dev hello_world.ko lib mnt root sbin sys usr
check.sh etc home media proc run srv tmp var
/ # /bin/busybox insmod hello_world.ko
/ #

COPY failed: stat /var/lib/docker/tmp/docker-builder076499369/files/nginx.conf: no such file or directory

I am running following version of docker ce
Server: Docker Engine - Community
Engine:
Version: 18.09.5
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: e8ff056dbc
Built: Thu Apr 11 04:50:00 2019
OS/Arch: linux/amd64
Experimental: false
Getting following error while building image
Removing intermediate container 40e7e0172f54
---> 5f2b3358b638 Step 5/10 : COPY files/nginx.conf /etc/nginx/nginx.conf COPY failed: stat
/var/lib/docker/tmp/docker-builder076499369/files/nginx.conf: no such
file or directory
Re-installing docker.
Setting up context.
Check that you have the following files structure:
|-- project
| |-- Dockerfile
| |-- files
| | |-- nginx.conf
Also make sure that next to the Dockerfile you do not have a file ".dockerignore" and if you have one make sure it does not contain an entry for "files" or "nginx.conf".
Then it should work.

Docker image created by Bazel does not have repository/tag, files are packed with strange names and do not run

I'm trying to pack an application compiled with Bazel into a Docker image, using Bazel.
I have an empty WORKSPACE file, the following main.cc file:
#include <stdio.h>
int main() { printf("Hello World\n"); }
and the following BUILD file (all in the same folder):
load("#bazel_tools//tools/build_defs/docker:docker.bzl", "docker_build")
cc_binary(
name = "hello",
srcs = ["main.cc"],
)
docker_build(
name = "hello_docker",
files = [":hello"],
cmd = ["./hello"],
)
Gist is available here.
When I run bazel run :hello, I can see "Hello World" successfully printed. Then I run bazel build :hello_docker.tar which is supposed to generate a full image for docker in bazel-bin/hello_docker.tar. Looks like it does.
Then I run:
$ docker load -i bazel-bin/hello_docker.tar
51525b594688: Loading layer [==================================================>] 10.24 kB/10.24 kB
Loaded image ID: sha256:252367f43640968343ecd78b2a3533c8ed99c4be66d73fc3ec6ccb137df19625
Then I list all images:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 b969ab9f929b 3 weeks ago 188 MB
docker/whalesay latest 6b362a9f73eb 21 months ago 247 MB
<none> <none> 252367f43640 292 years ago 8.048 kB
Looks like the image which was just loaded does not have any repository or tag associated with it. Why can that be and how do I fix that? The "created" value is huge as expected (Bazel clears timestamps for reproductibility).
When I look inside hello_docker.tar, I see something related to the expected repository/tag inside the repository file:
{
"bazel/": {
"hello_docker": "3d529b3ceeb0d9ef33f6225e655f3f5a0e061888f25cd6a3fac11604778ef6a8"
}
}
Another problem: when I try to run the image in a new container, it fails:
$ docker run -t -i 25236
docker: Error response from daemon: oci runtime error: exec: "./hello": stat ./hello: no such file or directory.
I looked inside the generated tar file one more time and found out that there is an executable here, but it's named o for some reason. Another attempt and a different error:
$ docker run -t -i 25236 ./o
write pipe: bad file descriptor
Strangely enough, if I pack that hello executable with my own Dockerfile like this, "Hello World" is printed as expected:
FROM ubuntu:14.04
ADD hello .
CMD ./hello
Can anyone suggest how to fix any of these three issues? I think that they're interconnect and I have wrong BUILD file (maybe I should somehow specify which Linux image to use as a base?). Recap:
Repository/tag name is not displayed after image generated by Bazel is imported into Docker.
hello file is added to the image under the name o.
Even when run as o, Dockered executable yields "bad file descriptor" message.
My software versions:
$ bazel version
Build label: 0.4.4
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Feb 1 18:54:21 2017 (1485975261)
Build timestamp: 1485975261
Build timestamp as int: 1485975261
$ docker version
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.2
Git commit: 6b644ec
Built: Mon, 19 Dec 2016 09:20:48 +1300
OS/Arch: linux/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.2
Git commit: 6b644ec
Built: Mon, 19 Dec 2016 09:20:48 +1300
OS/Arch: linux/amd64

Docker: Container command '/bin/sh' not found

When i try to build docker images using the command docker build -t opencv:2.4.11 . I get following error.
Sending build context to Docker daemon 189.8 MB
Step 1 : FROM ubuntu:trusty
---> b72889fa879c
Step 2 : RUN apt-get update
---> Running in 689f34e138c2
Container command '/bin/sh' could not be invoked.
My docker client and server version are:
Client:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64
Any idea?
I have softlinked my /var/lib/docker directory to one of directories present in my home. And that directory is owned by root. Is this the source of problem?
Before moving and softlinking it was fine. I ran out of space in my root partition and so I had to change it to my home partition.
And my home partition is ext4 file system.
Regards
It looks badly hosed.
I have softlinked my /var/lib/docker directory to one of directories present in my home.
I would recommend amending the daemon parameters to include -g your_other_directory instead. Then stop and restart Docker.
If it still doesn't work, delete both Docker directories, re-install, and start at the -g step again.

File copied by Docker seen as a directory

I'm trying to dockerize a Stardog 3.1.3 community edition server. The container fails to start because it sees a directory instead of a license file. For the record, I'm on Windows. These are the steps I'm following:
Create a data container
docker create -v /data/stardog:/data/stardog --name stardog_data busybox /bin/true
Copy the local license key to the data container (not done in the Dockerfile that is mentioned below as the license is environment specific)
docker cp .\stardog\stardog-license-key.bin stardog_data:/stardog-license-key.bin
Create an image based on the following Dockerfile
docker build -t me/stardog .
FROM java:openjdk-8-jdk
ENV STARDOG_VER stardog-3.1.3
ENV STARDOG_HOME /data/stardog
COPY ${LOCAL_PATH}/${STARDOG_VER}.zip /
RUN unzip ${STARDOG_VER}.zip
WORKDIR /${STARDOG_VER}
CMD rm $STARDOG_HOME/system.lock || true && bin/stardog-admin server start && (tail -f $STARDOG_HOME/stardog.log &) && while (pidof java > /dev/null); do sleep 1; done
Run a Stardog container
docker run -d -p 5820:5820 --volumes-from stardog_data --name stardog me/stardog
When I execute docker ps -a, I see that the container is stopped after a couple of seconds:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9559b22473e1 me/stardog "/bin/sh -c 'rm $STAR" 26 minutes ago Exited (1) 26 minutes ago stardog
2b929329e35e busybox "/bin/true" 32 minutes ago Created stardog_data
When I check the logs with docker logs stardog, I'm getting this:
com.clarkparsia.license.InvalidLicenseException: java.io.FileNotFoundException: /data/stardog/stardog-license-key.bin (Is a directory)
at com.clarkparsia.license.LicenseValidator.validate(LicenseValidator.java:157)
at com.complexible.stardog.StardogLicense.findLicense(StardogLicense.java:127)
at com.complexible.stardog.StardogLicense.<init>(StardogLicense.java:70)
at com.complexible.stardog.Stardog.<init>(Stardog.java:158)
at com.complexible.stardog.Stardog.initialize(Stardog.java:263)
at com.complexible.stardog.Stardog.initialize(Stardog.java:254)
at com.complexible.stardog.Stardog.buildServer(Stardog.java:247)
at com.complexible.stardog.cli.impl.ServerStart.call(ServerStart.java:144)
at com.complexible.stardog.cli.impl.ServerStart.call(ServerStart.java:47)
at com.complexible.stardog.cli.CLIBase.execute(CLIBase.java:54)
at com.complexible.stardog.cli.admin.CLI.main(CLI.java:194)
Caused by: java.io.FileNotFoundException: /data/stardog/stardog-license-key.bin (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at com.clarkparsia.license.LicenseValidator.validate(LicenseValidator.java:113)
... 10 more
Your Stardog license is invalid. Please contact support#clarkparsia.com for information on obtaining a new license.
It seems that the license file is considered to be a directory. What am I doing wrong?
I'm using the following Docker version:
Client:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 21:49:11 2016
OS/Arch: windows/amd64
Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 21:49:11 2016
OS/Arch: linux/amd64
This seems to be a Windows related problem. I've tried these exact same steps on a native Ubuntu (14.04) machine and it works as expected. I've filed this as a bug and hopefully this gets fixed soon.

Resources