Docker Community Forums

Share and learn in the Docker community.

Unexpected EOF when using Docker Rest API

docker
build
#1

hey
I am trying to build an image using Docker Rest API. However, I receive an unexpected EOF error message… The parameters of the json request are (I am using python):

{"dockerfile": docker_file_path, "t": name}

The image I’m using as base to perform this build is one that already exists in my repository. When I perform the build via command line with sudo docker build -t n . , it works perfectly.

(Gary Forghetti) #2

You are getting the EOF because the Docker API is expecting the contents of the Dockerfile passed to the Docker engine API.

You are not showing the command or code you are using to build your image so I can’t “see” what you are doing.

You have to pass the Dockerfile as part of the “payload” to the Docker API.

Example using curl

Note: I have my Docker daemon listening on tcp://127.0.0.1:5000 so I could curl the API locally.

In my docker.service file I have:

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:5000

My Dockerfile

🐳  gforghetti@172.28.128.3:[~] $ cat Dockerfile
FROM alpine:latest

CMD echo 'Hello World!'

Create a binary archive for the Dockerfile

🐳  gforghetti@172.28.128.3:[~] $ tar zcvf dockerfile.tar.gz Dockerfile
Dockerfile

Call the Docker API to build the image

🐳  gforghetti@172.28.128.3:[~] $ curl -v -H 'Content-Type:application/tar' --data-binary '@dockerfile.tar.gz' http://127.0.0.1:5000/build?t=gforghetti/my_app:1.0.0
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> POST /build?t=gforghetti/my_app:1.0.0 HTTP/1.1
> Host: 127.0.0.1:5000
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Type:application/tar
> Content-Length: 172
>
* upload completely sent off: 172 out of 172 bytes
< HTTP/1.1 200 OK
< Api-Version: 1.39
< Content-Type: application/json
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/18.09.1 (linux)
< Date: Tue, 05 Feb 2019 20:46:12 GMT
< Transfer-Encoding: chunked
<
{"stream":"Step 1/2 : FROM alpine:latest"}
{"stream":"\n"}
{"status":"Pulling from library/alpine","id":"latest"}
{"status":"Pulling fs layer","progressDetail":{},"id":"6c40cc604d8e"}
{"status":"Downloading","progressDetail":{"current":27877,"total":2754728},"progress":"[\u003e                                                  ]  27.88kB/2.755MB","id":"6c40cc604d8e"}
{"status":"Downloading","progressDetail":{"current":1624825,"total":2754728},"progress":"[=============================\u003e                     ]  1.625MB/2.755MB","id":"6c40cc604d8e"}
{"status":"Verifying Checksum","progressDetail":{},"id":"6c40cc604d8e"}
{"status":"Download complete","progressDetail":{},"id":"6c40cc604d8e"}
{"status":"Extracting","progressDetail":{"current":32768,"total":2754728},"progress":"[\u003e                                                  ]  32.77kB/2.755MB","id":"6c40cc604d8e"}
{"status":"Extracting","progressDetail":{"current":1474560,"total":2754728},"progress":"[==========================\u003e                        ]  1.475MB/2.755MB","id":"6c40cc604d8e"}
{"status":"Extracting","progressDetail":{"current":2754728,"total":2754728},"progress":"[==================================================\u003e]  2.755MB/2.755MB","id":"6c40cc604d8e"}
{"status":"Pull complete","progressDetail":{},"id":"6c40cc604d8e"}
{"status":"Digest: sha256:b3dbf31b77fd99d9c08f780ce6f5282aba076d70a513a8be859d8d3a4d0c92b8"}
{"status":"Status: Downloaded newer image for alpine:latest"}
{"stream":" ---\u003e caf27325b298\n"}
{"stream":"Step 2/2 : CMD echo 'Hello World!'"}
{"stream":"\n"}
{"stream":" ---\u003e Running in 8344e3468637\n"}
{"stream":"Removing intermediate container 8344e3468637\n"}
{"stream":" ---\u003e 46a0a9f9e4c4\n"}
{"aux":{"ID":"sha256:46a0a9f9e4c47f08bc52b80e0119a1ce1e96e980d1137e54110501fc7743137c"}}
{"stream":"Successfully built 46a0a9f9e4c4\n"}
{"stream":"Successfully tagged gforghetti/my_app:1.0.0\n"}
* Connection #0 to host 127.0.0.1 left intact

Display the images

🐳  gforghetti@172.28.128.3:[~] $ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
gforghetti/my_app   1.0.0               e9155cb5cac7        5 seconds ago       5.53MB
alpine              latest              caf27325b298        5 days ago          5.53MB
#3

Thanks got the problem and its solved :slight_smile: