Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attaching to a docker container with base image scratch?

Tags:

docker

I have a docker file as follows:

FROM scratch

ARG VERSION=NOT_SET
ENV VERSION $VERSION

COPY foobar foobar
COPY foobar-*.yaml /etc/
COPY jwt/ /etc/jwt/

EXPOSE 8082

ENTRYPOINT ["./foobar"]
CMD ["-config", "/etc/foobar-local.yaml"]

Now, docker ps shows the following:

CONTAINER ID        IMAGE                                                               COMMAND                  CREATED              STATUS              PORTS                         NAMES
653a9b287eb6        7693481.dkr.ecr.us-east-1.amazonaws.com/foobar:0.0.1           "./foobar -config /e"   About a minute ago   Up About a minute                                 foobar

When I try to exec to this container with the following command:

sudo docker exec -it 653a9b287eb6 /bin/bash

it shows the following error:

rpc error: code = 2 desc = oci runtime error: 
exec failed: exec: "/bin/bash": stat /bin/bash: no such file or directory
like image 498
John Dui Avatar asked Oct 24 '16 06:10

John Dui


People also ask

What is scratch base image?

When building Docker containers you define your base image in your dockerfile. The scratch image is the smallest possible image for docker. Actually, by itself it is empty (in that it doesn't contain any folders or files) and is the starting point for building out images.

Does Docker image include base image?

A Docker image has many layers, and each image includes everything needed to configure a container environment -- system libraries, tools, dependencies and other files. Some of the parts of an image include: Base image. The user can build this first layer entirely from scratch with the build command.


1 Answers

You need to add a shell to your empty base image (SCRATCH) in order to attach to it.

Right now, your image only include an executable, which is not enough.

As mentioned in issue 17896

FROM scratch literally is an empty, zero-byte image / filesystem, where you add everything yourself.
See for example, the hello-world which, produces an image that's 860 bytes total.

If you need a shell to attach to it through docker exec, start from a small image like Alpine (which has only /bin/sh though: you would need apk add bash to add bash, as commented below by user2915097).

like image 72
VonC Avatar answered Oct 01 '22 21:10

VonC