Docker exec. How to use shell-commands in container without entering? - docker

Can someone explain me, how can I use sh-commands inside container without enter that container?
I use a shell script at my host. I want this shell-script to enter one of my container and then curl post to another container through overall network. So, my problem is that when i tring to do something like:
docker exec -ti nodejs sh "curl -X POST \
http://tgbot:3017/deploy \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'message=Prod has been updated!'"
I have in console:
sh: 0: Can't open curl -X POST http://tgbot:3017/ -H 'Content-Type: application/x-www-form-urlencoded' -H 'cache-control: no-cache' -d 'message=Prod has been updated!'
failed to resize tty, using default size
Or mayby I can curl into docker network right from host somehow?

You can just use Docker exec command on the host machine.
docker exec -it <container name> <command>

Related

Is there a way to get tags of a docker image on github container registry (ghcr.io) via curl or gh command?

Is there a way to get tags of a docker image on github container registry via curl or gh command?
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/${ORG}/packages/container/${CONTAINER_IMG}
I have tried above but it does not give me docker tags for the iamge.
I am expecting to get the docker tags of ghcr.io containers.

TensorFlow model server - Could not resolve host POST

I am new to TensorFlow (using 1.13) and trying to build a TF model and serve it on a docker tensor flow model server.
I have exported my model, installed docker and started my docker container with the command:
docker run -p 8501:8501 --name SN_TFlow
--mount type=bind,source=/tmp/service_model/export,target=/models
-e MODEL_NAME=1596551653 -t tensorflow/serving &
I can see my container running and the line: "I tensorflow_serving/model_servers/server.cc:375] Exporting HTTP/REST API at:localhost:8501 ..." in the client which seems to indicate all is up and running according to the doc.
However when I try to test my model with the curl command:
$ curl -d ‘{"test_value": [40]}' \ -X POST http://localhost:8501/1/models/1596551653:predict
I get a message saying:
URL bad/illegal format or missing url
Could not resolve host POST
and I get a 404 message.
I also tried simply curl http://localhost:8501/models/1/1596551653 but also get Not found.
Any idea what I am missing? Thanks
The problem I observe in your code is the \ in the middle of the curl command.
The backslash, \ should occur at the end of the line, if the command is more than one line.
So, the below command,
$ curl -d ‘{"test_value": [40]}' \ -X POST
http://localhost:8501/1/models/1596551653:predict
should be changed as shown below (move the backslash to the end) :
$ curl -d ‘{"test_value": [40]}' -X POST \
http://localhost:8501/1/models/1596551653:predict
Also, we suggest you to upgrade to the Latest Version of Tensorflow in 1.x, which is 1.15 or to 2.3.0.

Unable to start kurento media server with docker

I'm trying to run kurent-media-server, by following the instructions found here:
https://hub.docker.com/r/kurento/kurento-media-server
I've followed them, but I am still unable to connect to the server.
After running
$ docker run --name kms -d -p 8888:8888 \
kurento/kurento-media-server
$ curl -i -N \
-H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Host: 127.0.0.1:8888" \
-H "Origin: 127.0.0.1" \
http://127.0.0.1:8888/kurento
I get curl: (56) Recv failure: Connection reset by peer, instead of
HTTP/1.1 500 Internal Server Error
Server: WebSocket++/0.7.0
How can I fix this? I seem to have done done everything properly.
Try using latest image of kurento-media-server docker. I am using version 6.13.2 and it works fine for me.

Jenkins Docker Sidecar with Container Running a daemon command

I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.
In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.
stage('Run Zap Proxy'){
docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
/* Wait until mysql service is up */
sh """
zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
"""
}
docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
sh """
curl -k -x http://proxy:8090 \
-X POST https://my.fqdn.net/api/rest/sessions \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"username":"username","password":"password"}'
"""
sh 'sleep 2m'
sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
stash includes: 'report.html', name: 'report'
}
}
}
I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers stages are complete.
You could directly pass the zap command in the withRun part:
stage('Run Zap Proxy'){
docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
sh """
curl -k -x http://proxy:8090 \
-X POST https://my.fqdn.net/api/rest/sessions \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"username":"username","password":"password"}'
"""
sh 'sleep 2m'
sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
stash includes: 'report.html', name: 'report'
}
}
}
withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.

How to execute "docker checkpoint create container_id checkpoint_id" using curl?

At the moment of writing, docker checkpoint feature is still in experimental phase so there is no official (HTTP) API documentation. Nonetheless, there is an endpoint on the docker daemon that can accept an HTTP request, as it is the one that docker cli uses.
Based on the related docker source code it should be something like
sudo curl -X POST --unix-socket /var/run/docker.sock http://localhost/v1.32/containers/20fb4f16ff10/checkpoints
but this does not work. Any ideas what I may be missing?
The create options is missing.
curl --unix-socket /var/run/docker.sock \
-H "Content-Type: application/json" \
-d '{"CheckpointID": "noting"}' \
-X POST http:/v1.32/containers/20fb4f16ff10/checkpoints

Resources