"404 page not found" when exec `curl --unix-socket /var/run/docker.sock http:/containers/json` - docker

docker version: 1.11.2
curl version: 7.50.3 (x86_64-pc-linux-gnu) libcurl/7.50.3 OpenSSL/1.0.1e zlib/1.2.7
/usr/local/sbin/bin/curl --unix-socket /var/run/docker.sock http://images/json -v
* Trying /var/run/docker.sock...
* Connected to images (/var/run/docker.sock) port 80 (#0)
> GET /json HTTP/1.1
> Host: images
> User-Agent: curl/7.50.3
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Thu, 22 Sep 2016 06:11:52 GMT
< Content-Length: 19
<
404 page not found
* Curl_http_done: called premature == 0
* Connection #0 to host images left intact
Is there anything wrong with my docker daemon? How can I get the containers info from the docker unix-socket?
docker deamon is absolutely started.

I followed this page:https://docs.docker.com/engine/reference/api/docker_remote_api/#/v1-23-api-changes, its suggestion us to use curl 7.40 or later, command curl --unix-socket /var/run/docker.sock http:/containers/json. You can found that there is a unavild URL http:/containers/json in this command.
Then I download the newest curl 7.50.3, the key of this problem is the curl's version, we should exec like below:
curl --unix-socket /var/run/docker.sock http://localhost/images/json
More detail watch this page.https://superuser.com/questions/834307/can-curl-send-requests-to-sockets. Hope it help some other people who confused.

Related

How to start an interactive shell with docker container using restful API?

I'm trying to learn about the Docker Engine restful API, v1.41, but that's a problem. I managed to use cURL successfully to send all HTTP requests concerning containers, images, volumes and network, but it's impossible to me to use them for exec instances.
I read in the official documentation that when I use the docker exec command, he behaves the same way as calling POST /containers/:id/exec and then POST /exec/:id/start.
Now, in order to execute docker exec -it my_container bash that's what I did and got:
[claudio#gulliver ~]$ curl -X POST --unix-socket /run/docker.sock\
http/containers/18d7dee7470d/exec\
-H "Content-Type: application/json"\
-d '{
"AttachStdin":true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"Cmd":["bash"]
}'
{"Id": "853938b2621606f85c04409ec7e345b884d46b95985a4fca0e8ddf28e20e1f79"}
[claudio#gulliver ~]$ curl -X POST --unix-socket /run/docker.sock\
http/exec/853938b2621606f85c04409ec7e345b884d46b95985a4fca0e8ddf28e20e1f79/start\
-H "Content-Type: application/json"\
-d '{
"Detach":false,
"Tty":true
}' --verbose
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying /run/docker.sock:0...
* Connected to http () port 80 (#0)
> POST /exec/853938b2621606f85c04409ec7e345b884d46b95985a4fca0e8ddf28e20e1f79/start HTTP/1.1
> Host: http
> User-Agent: curl/7.85.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 28
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/vnd.docker.raw-stream
< Api-Version: 1.41
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/20.10.21 (linux)
* no chunk, no close, no size. Assume close to signal end
<
And from now I cannot do anything, just interrupt the process.
Is there a way I don't know to interact with this?

Not being able to inference TensorFlow model hosted by kfserving component in Kubeflow

Hi so I am using kfserving v.0.5.1 component for hosting the model. I am able to download and deploy model from s3 but facing issue when try to access it.
After deployment kfserving outputted the following endpoint
http://recommendation-model.kubeflow-user-example-com.example.com
which I was not able to access it from outside and inside the node. After looking around I set my ingress-gateway to LoadBalancer from NodePort and added sslip.io to config-map config-domain of knative-serving
I followed knative-dn-config
<IPofMyLB>.sslip.io: ""
after that I try to inference model but getting no error or response from server
curl -d '{"instances": ["abc"]}' -X POST http://recommendation-model.kubeflow-user-example-com.<IPofMyLB>.sslip.io/v1/models/recommendation-model:predict
I try to simply get the inference endpoint and output is this:
curl -v -X GET http://recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying ELBIP...
* TCP_NODELAY set
* Connected to recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io (ELBIP) port 80 (#0)
> GET / HTTP/1.1
> Host: recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 302 Found
< content-type: text/html; charset=utf-8
< location: /dex/auth?client_id=kubeflow-oidc-authservice&redirect_uri=%2Flogin%2Foidc&response_type=code&scope=profile+email+groups+openid&state=MTYyMjY0MjU5M3xFd3dBRUV4MVVERkljREpRVUc1SVdXeDFaVkk9fOEnkjCWGNj6WPOgFhv2BUwNSKHsYyBR2kyj9_0geX2f
< date: Wed, 02 Jun 2021 14:03:13 GMT
< content-length: 269
< x-envoy-upstream-service-time: 1
< server: istio-envoy
<
Found.
* Connection #0 to host recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io left intact
* Closing connection 0
(base) ahsan#Ahsans-MacBook-Pro kfserving % curl -v -X GET http://recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying ELBIP...
* TCP_NODELAY set
* Connected to recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io (ELBIP) port 80 (#0)
> GET / HTTP/1.1
> Host: recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 302 Found
< content-type: text/html; charset=utf-8
< location: /dex/auth?client_id=kubeflow-oidc-authservice&redirect_uri=%2Flogin%2Foidc&response_type=code&scope=profile+email+groups+openid&state=MTYyMjY0MzE3OXxFd3dBRUhOdmFrSk9iVkU0Wms1VmMzVnhXbkU9fECJ3_U0SaWkR441eIWq-AJbFAV29-2Bk8uxPAOxPJD0
< date: Wed, 02 Jun 2021 14:12:59 GMT
< content-length: 269
< x-envoy-upstream-service-time: 1
< server: istio-envoy
<
Found.
* Connection #0 to host recommendation-model.kubeflow-user-example-com.ELBIP.sslip.io left intact
* Closing connection 0
model directory structure
recommendation_model/
└── 1
├── assets
├── keras_metadata.pb
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index
Not sure how to get serving to work as this is the last part of my pipeline
When visiting the inferenceservice through the LoadBalancer, essentially the istio-ingressgateway, your request has an extra layer of control compared to the NodePort, which is dictated by the Istio security policy.
The response message of your curl indicates that you have an Istio installation with DEX authentication.
The istio-dex guide has examples of how to set the cookie for authenticating your inference request.

Cannot retrieve the stats of my docker containers using Docker APIs

I have several containers that are running on my Centos7 VM and I would like to retrieve their CPU and Memory usage using the following command:
echo -e "GET /containers/(container_name)/stats HTTP/1.0\r\n" | \
nc -U /var/run/docker.sock
However, I just receive the following message without any statistics:
HTTP/1.0 200 OK
Server: Docker/1.10.3 (linux)
Date: Sun, 22 Jan 2017 15:53:49 GMT
Content-Type: text/plain; charset=utf-8
The "containers/(container_name)/top" command works fine.
Can you please help me to understand why I don't receive this container's statistics?
Command to use get the stats of the container:
curl -X GET http://127.0.0.1:6000/containers/<container_id>/stats
The stats will be displayed for every second.
Stats can be fetched only for running containers.
Refer this :
how to configure docker daemon port.

Error uploading image into Docker Registry using API v2

I am trying to upload Docker image (tarball) into private Docker registry using following API.
I am following the documentation here: http://docs.docker.com/registry/spec/api/
Step 1: Initiate the upload and get location URL
$ curl -v -X POST http://localhost:5000/v2/hello-world/blobs/uploads/ * About to connect() to localhost port 5000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> POST /v2/hello-world/blobs/uploads/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
>
< HTTP/1.1 202 Accepted
< Content-Length: 0
< Docker-Distribution-Api-Version: registry/2.0
< Docker-Upload-Uuid: dd319793-f017-45b3-afe4-c8102363a8df
< Location: http://localhost:5000/v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D
< Range: 0-0
< Date: Tue, 27 Oct 2015 22:25:21 GMT
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host localhost left intact
Step 2: Use location URL to upload the actual Docker image
$ curl -v -H "Content-type: application/octet-stream" -H "Content-Length: 13824" --data-binary #/tmp/hello-world.tar -X PUT -L "http://localhost:5000/v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D&digest=tarsum.v2+sha256:97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde"
* About to connect() to localhost port 5000 (#0)
* Trying ::1...
* Connected to localhost (::1) port 5000 (#0)
> PUT /v2/hello-world/blobs/uploads/dd319793-f017-45b3-afe4-c8102363a8df?_state=SB2605fFM_7KNkYTHjVrVQVT62dufwXNTw9QzO2_aRR7Ik5hbWUiOiJoZWxsby13b3JsZCIsIlVVSUQiOiJkZDMxOTc5My1mMDE3LTQ1YjMtYWZlNC1jODEwMjM2M2E4ZGYiLCJPZmZzZXQiOjAsIlN0YXJ0ZWRBdCI6IjIwMTUtMTAtMjdUMjI6MjU6MjEuMTM0MTI5MDNaIn0%3D&digest=tarsum.v2+sha256:97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:5000
> Accept: */*
> Content-type: application/octet-stream
> Content-Length: 13824
> Expect: 100-continue
>
* Done waiting for 100-continue
< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< Date: Tue, 27 Oct 2015 22:29:02 GMT
< Content-Length: 131
* HTTP error before end of send, stop sending
<
{"errors":[{"code":"DIGEST_INVALID","message":"provided digest did not match uploaded content","detail":"digest parsing failed"}]}
* Closing connection 0
Also, I am using sha256sum as follows:
$ sha256sum /tmp/hello-world.tar
97bbb955c700a6414fd48ae147986e9b42c0508c8a766cea61e7e3badf0f7dde /tmp/hello-world.tar
What I am possibly doing wrong here? How to get around DIGEST_INVALID error?
Here is a simple example that should get you on track:
local reponame=foo/bar
local uploadURL
local numBytes=10000000 # 10 Megabytes
uploadURL=$(curl -siL -X POST "https://registrydomain/v2/$reponame/blobs/uploads/" | grep 'Location:' | cut -d ' ' -f 2 | tr -d '[:space:]')
blobDigest="sha256:$(head -c $numBytes /dev/urandom | tee upload.tmp | shasum -a 256 | cut -d ' ' -f 1)"
echo "Uploading Blob of 10 Random Megabytes"
time curl -T upload.tmp --progress-bar "$uploadURL&digest=$blobDigest" > /dev/null

HTTP Request from Dockerfile not successful

I'm playing around with Docker and am trying to get a Dockerfile working running ubuntu and nginx.
The result from "docker build" is that curl is unable to do a HTTP request at localhost, however if I later start the container created from the Dockerfile it works just fine..
What could possibly be the issue here?
See the Dockerfile below:
$ cat Dockerfile
FROM ubuntu:14.10
RUN apt-get update
RUN apt-get install -y curl nginx
RUN service nginx start
RUN echo "niklas9 was here" > /usr/share/nginx/html/index.html
RUN /usr/bin/curl -v "http://localhost/"
Result from "docker build":
$ sudo docker.io build .
...
Step 5 : RUN /usr/bin/curl -v "http://localhost/"
---> Running in 46f773be22a2
* Hostname was NOT found in DNS cache
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ::1...
* connect to ::1 port 80 failed: Connection refused
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 80 failed: Connection refused
* Failed to connect to localhost port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 80: Connection refused
2014/11/26 22:47:38 The command [/bin/sh -c /usr/bin/curl -v "http://localhost/"] returned a non-zero code: 7
Results from starting the container and attaching into it:
root#65c55d5974cb:/# curl -v "http://localhost/"
* Hostname was NOT found in DNS cache
* Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
* Server nginx/1.6.2 (Ubuntu) is not blacklisted
< Server: nginx/1.6.2 (Ubuntu)
< Date: Wed, 26 Nov 2014 21:50:16 GMT
< Content-Type: text/html
< Content-Length: 17
< Last-Modified: Wed, 26 Nov 2014 21:38:11 GMT
< Connection: keep-alive
< ETag: "54764843-11"
< Accept-Ranges: bytes
<
niklas9 was here
* Connection #0 to host localhost left intact
I'm running Ubuntu 14 with docker installed with apt-get, see version below.
$ docker.io --version
Docker version 0.9.1, build 3600720
Fundamentally, you should not be thinking of firing up your service at build time.
Dockerfile RUN commands are intended to create some state for the final container you are trying to make. Each command creates a new container layer, based on the one before, and Docker caches them to speed things up, so any given RUN command may not actually run at all for a build, unless the things that go before it have changed.
Some notes from Docker on how this works
After the line
RUN service nginx start
is executed, only the changes in the file system are persistent.
The nginx process isn't available when the next line of the dockerfile is executed.
It would work like that, but if you want the nginx process to be started in the container, you would need to add a CMD at the end.
FROM ubuntu:14.10
RUN apt-get update
RUN apt-get install -y curl nginx
RUN echo "niklas9 was here" > /usr/share/nginx/html/index.html
RUN service nginx start && /usr/bin/curl -v "http://localhost/"

Resources