how to support multiple languages on Alpine Linux 3.6.0? - localization

I am using Alpine Linux 3.6.0 as my base OS in a docker container and running a Spring Boot project.
When I do one of the following in my terminal:
curl -X GET http://localhost:10000/sco/scorpius -H 'accept-language: ja-JP'
curl -X GET http://localhost:10000/sco/scorpius -H 'accept-language: zh-CN'
I get something like this as my HTTP response:
{"message":"å ´åã«ãã£ã¦ã¯ãä¸é¨ããã¹ã}
when it should be:
{"message":"時に何かがすべて"}
How do I add the japanese, chinese, etc. language packages for Alpine? I can not seem to find any here: https://pkgs.alpinelinux.org/packages

Related

Spring cloud skipper Cannot upload a package via REST API

I am following a doc to upload a package into Skipper Server at https://docs.spring.io/spring-cloud-skipper/docs/current-SNAPSHOT/reference/htmlsingle/#resources-package
Here is a package: Helloworld
This is curl command as
$ curl 'http://localhost:7577/api/package/upload' -i -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
-H 'Accept: application/json' \
-F 'data=/home/user1/helloworld-1.0.0.zip'
But still cannot upload a package. Please help me what's correct to upload a package to Skipper via REST API.
P.s: By using a POSTMAN but It's also impossible.
I found it how to do on old doc from spring team.
Post here if someone is needed.
https://docs.spring.io/spring-cloud-skipper/docs/1.0.0.BUILD-SNAPSHOT/reference/html/api-guide-resources.html#resources-package

Busybox wget to download jar fails with an error "wget: server returned error: HTTP/1.1 307 Temporary Redirect"

I am using adoptopenjdk/openjdk11:alpine-jre base image for java and trying below instruction inside my Dockerfile,
RUN wget -O dd-java-agent.jar "https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.datadoghq&a=dd-java-agent&v=LATEST"
which produces an error: Connecting to repository.sonatype.org (18.208.14.211:443) wget: server returned error: HTTP/1.1 307 Temporary Redirect
Is there a way to download the latest version of jar file from nexus using wget utility available with Busybox?
Alpine version: v3.12.0 | Busybox version: v1.31.1
Note: If I specify the exact version of jar like RUN wget -O dd-java-agent.jar 'https://repository.sonatype.org/service/local/repositories/central-proxy/content/com/datadoghq/dd-java-agent/0.38.0/dd-java-agent-0.38.0.jar'
it succeeded. I am aware of other option is to use curl in this case. Just trying to keep it simple and avoiding the installation of curl, its usage, and then removal.
BusyBox replaces Wget with a compact implementation of its own, which does not support all the security features and options such as https redirects. Worse, the BusyBox TLS library does not support certificate validation nor the option --no-check-certificate. Issue discussed on Git https://github.com/sabotage-linux/sabotage/issues/252 6 years ago but actually never fixed.
There is no solution with busybox wget other then:
adding the real wget to your build
adding curl
Starting from BusyBox 1.34.0 (19 August 2021) the 307 and 308 redirects are supported. Commit e71ea6c1f84318d8655a5783736288695174f596

How do I delete a docker image from docker hub via command line?

I create docker image for testing in my Jenkins pipeline, uploading this to Docker hub and deploy those to Kubernetes. At the end of the testing process, I want to delete the test image from Docker hub (not from test machine). How do I delete docker hub image from command line?
Use the Docker Hub API as documented in:
https://docs.docker.com/v1.7/reference/api/docker-io_api/#delete-a-user-repository
I've just tested a delete of a test image with curl:
curl -X DELETE -u "$user:$pass" https://index.docker.io/v1/repositories/$namespace/$reponame/
Replace $user and $pass with your user and password on the Docker Hub, respectively; and replace $namespace (in my case it's the same as the $user) and $reponame with the image name (in my case was test).
You can delete any <TAG> from your Docker Hub <REPO> by using curl and REST API to the Docker Hub website (at https://hub.docker.com/v2/) rather that to the Docker Hub registry (at docker.io). So if you are not afraid of using an undocumented API, this currently works:
curl -i -X DELETE \
-H "Accept: application/json" \
-H "Authorization: JWT $HUB_TOKEN" \
https://hub.docker.com/v2/repositories/<HUB_USERNAME>/<REPO>/tags/<TAG>/
The HUB_TOKEN is a JSON Web Token passed using Authorization HTTP header, and it can be obtained by posting your credendials in JSON format to the /v2/users/login/ Docker Hub endpoint:
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"$HUB_USERNAME\", \"password\": \"$HUB_PASSWORD\"}" https://hub.docker.com/v2/users/login/ | jq -r .token)
2FA => Personal Access Token
Note than when you have 2FA enabled, you’ll need a personal access token (the only password accepted by the API when using 2FA).
Dockerhub has a REST backEnd, then you can use it... it is just skipping the FE...
For example:
export USERNAME=myuser
export PASSWORD=mypass
export ORGANIZATION=myorg (if it's personal, then it's your username)
export REPOSITORY=myrepo
export TAG=latest
curl -u $USERNAME:$PASSWORD -X "DELETE" https://cloud.docker.com/v2/repositories/$ORGANIZATION/$REPOSITORY/tags/$TAG/
This will delete one tag...
In my case, I have microservices, then the REPOSITORY = the Microservice Name...
If I want to delete all the older images, I can iterate on this....
For any PowerShell friends.
$params = #{username='mickey';password='minnie'}
$response = Invoke-RestMethod -Uri https://hub.docker.com/v2/users/login/ -Method POST -Body $params
$token = $response.token;
$orgName = "mickey" #organization or user name
$repoName = "disney"
$Uri = $("https://hub.docker.com/v2/repositories/$orgName/$repoName/")
Invoke-WebRequest -Method Delete -Uri $Uri -Headers #{Authorization="JWT " + $token; Accept= 'application/json' }
It is possible. For a shortcut, Open dev tools in Chrome, go to the network tab. Delete a tag manually from Docker Hub. You will see a request on the network tab in dev tools that goes to https://cloud.docker.com/v2/repositories//tags/. Just right click on that request, Copy, Copy as Curl. It should look something like this...
curl "https://cloud.docker.com/v2/repositories//tags//" -X DELETE -H 'Pragma: no-cache' -H 'Origin: https://cloud.docker.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Referer: https://cloud.docker.com/user/repository/registry-1.docker.io/reponame/tags' -H 'Cookie: ' --compressed
You can now use the new BETA (as of 2022-01) Docker Hub API
https://docs.docker.com/docker-hub/api/latest/
and the docker-hub CLI tool among a few other options.
hub-tool login
hub-tool tag rm myrepo/myimage:mytag

How to get a list of images on docker registry v2

I'm using docker registry v1 and I'm interested in migrating to the newer version, v2. But I need some way to get a list of images present on registry; for example with registry v1 I can execute a GET request to http://myregistry:5000/v1/search? and the result is:
{
"num_results": 2,
"query": "",
"results": [
{
"description": "",
"name": "deis/router"
},
{
"description": "",
"name": "deis/database"
}
]
}
But I can't find on official documentation something similar to get a list of image on registry. Anybody knows a way to do it on new version v2?
For the latest (as of 2015-07-31) version of Registry V2, you can get this image from DockerHub:
docker pull distribution/registry:master
List all repositories (effectively images):
curl -X GET https://myregistry:5000/v2/_catalog
> {"repositories":["redis","ubuntu"]}
List all tags for a repository:
curl -X GET https://myregistry:5000/v2/ubuntu/tags/list
> {"name":"ubuntu","tags":["14.04"]}
If the registry needs authentication you have to specify username and password in the curl command
curl -X GET -u <user>:<pass> https://myregistry:5000/v2/_catalog
curl -X GET -u <user>:<pass> https://myregistry:5000/v2/ubuntu/tags/list
you can search on
http://<ip/hostname>:<port>/v2/_catalog
Get catalogs
Default, registry api return 100 entries of catalog, there is the code:
When you curl the registry api:
curl --cacert domain.crt https://your.registry:5000/v2/_catalog
it equivalents with:
curl --cacert domain.crt https://your.registry:5000/v2/_catalog?n=100
This is a pagination methond.
When the sum of entries beyond 100, you can do in two ways:
First: give a bigger number
curl --cacert domain.crt https://your.registry:5000/v2/_catalog?n=2000
Second: parse the next linker url
curl --cacert domain.crt https://your.registry:5000/v2/_catalog
A link element contained in response header:
curl --cacert domain.crt https://your.registry:5000/v2/_catalog
response header:
Link: </v2/_catalog?last=pro-octopus-ws&n=100>; rel="next"
The link element have the last entry of this request, then you can request the next 'page':
curl --cacert domain.crt https://your.registry:5000/v2/_catalog?last=pro-octopus-ws
If the response header contains link element, you can do it in a loop.
Get Images
When you get the result of catalog, it like follows:
{
"repositories": [
"busybox",
"ceph/mds"
]
}
you can get the images in every catalog:
curl --cacert domain.crt https://your.registry:5000/v2/busybox/tags/list
returns:
{"name":"busybox","tags":["latest"]}
The latest version of Docker Registry available from https://github.com/docker/distribution supports Catalog API. (v2/_catalog). This allows for capability to search repositories
If interested, you can try docker image registry CLI I built to make it easy for using the search features in the new Docker Registry distribution (https://github.com/vivekjuneja/docker_registry_cli)
This has been driving me crazy, but I finally put all the pieces together. As of 1/25/2015, I've confirmed that it is possible to list the images in the docker V2 registry ( exactly as #jonatan mentioned, above. )
I would up-vote that answer, if I had the rep for it.
Instead, I'll expand on the answer. Since registry V2 is made with security in mind, I think it's appropriate to include how to set it up with a self signed cert, and run the container with that cert in order that an https call can be made to it with that cert:
This is the script I actually use to start the registry:
sudo docker stop registry
sudo docker rm -v registry
sudo docker run -d \
-p 5001:5001 \
-p 5000:5000 \
--restart=always \
--name registry \
-v /data/registry:/var/lib/registry \
-v /root/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
-e REGISTRY_HTTP_DEBUG_ADDR=':5001' \
registry:2.2.1
This may be obvious to some, but I always get mixed up with keys and certs. The file that needs to be referenced to make the call #jonaton mentions above**, is the domain.crt listed above. ( Since I put domain.crt in /root, I made a copy into the user directory where it could be accessed. )
curl --cacert ~/domain.crt https://myregistry:5000/v2/_catalog
> {"repositories":["redis","ubuntu"]}
**The command above has been changed: -X GET didn't actually work when I tried it.
Note: https://myregistry:5000 ( as above ) must match the domain given to the cert generated.
We wrote a CLI tool for this purpose: docker-ls It allows you to browse a docker registry and supports authentication via token or basic auth.
Here is a nice little one liner (uses JQ) to print out a list of Repos and associated tags.
If you dont have jq installed you can use: brew install jq
# This is my URL but you can use any
REPO_URL=10.230.47.94:443
curl -k -s -X GET https://$REPO_URL/v2/_catalog \
| jq '.repositories[]' \
| sort \
| xargs -I _ curl -s -k -X GET https://$REPO_URL/v2/_/tags/list
Install registry:2.1.1 or later (you can check the last one, here) and use GET /v2/_catalog to get list.
https://github.com/docker/distribution/blob/master/docs/spec/api.md#listing-repositories
Lista all images by Shell script example:
https://gist.github.com/OndrejP/a2386d08e5308b0776c0
I had to do the same here and the above works except I had to provide login details as it was a local docker repository.
It is as per the above but with supplying the username/password in the URL.
curl -k -X GET https://yourusername:yourpassword#theregistryURL/v2/_catalog
It comes back as unformatted JSON.
I piped it through the python formatter for ease of human reading, in case you would like to have it in this format.
curl -k -X GET https://yourusername:yourpassword#theregistryURL/v2/_catalog | python -m json.tool
Here's an example that lists all tags of all images on the registry. It handles a registry configured for HTTP Basic auth too.
THE_REGISTRY=localhost:5000
# Get username:password from docker configuration. You could
# inject these some other way instead if you wanted.
CREDS=$(jq -r ".[\"auths\"][\"$THE_REGISTRY\"][\"auth\"]" .docker/config.json | base64 -d)
curl -s --user $CREDS https://$THE_REGISTRY/v2/_catalog | \
jq -r '.["repositories"][]' | \
xargs -I #REPO# curl -s --user $CREDS https://$THE_REGISTRY/v2/#REPO#/tags/list | \
jq -M '.["name"] + ":" + .["tags"][]'
Explanation:
extract username:password from .docker/config.json
make a https request to the registry to list all "repositories"
filter the json result to a flat list of repository names
for each repository name:
make a https request to the registry to list all "tags" for that "repository"
filter the stream of result json objects, printing "repository":"tag" pairs for each tag found in each repository
Using "/v2/_catalog" and "/tags/list" endpoints you can't really list all the images. If you pushed a few different images and tagged them "latest" you can't really list the old images! You can still pull them if you refer to them using digest "docker pull ubuntu#sha256:ac13c5d2...". So the answer is - there is no way to list images you can only list tags which is not the same
I wrote an easy-to-use command line tool for listing images in various ways (like list all images, list all tags of those images, list all layers of those tags).
It also allows you to delete unused images in various ways, like delete only older tags of a single image or from all images etc. This is convenient when you are filling your registry from a CI server and want to keep only latest/stable versions.
It is written in python and does not need you to download bulky big custom registry images.
If some on get this far.
Taking what others have already said above. Here is a one-liner that puts the answer into a text file formatted, json.
curl "http://mydocker.registry.domain/v2/_catalog?n=2000" | jq . - > /tmp/registry.lst
This looks like
{
"repositories": [
"somerepo/somecontiner",
"somerepo_other/someothercontiner",
...
]
}
You might need to change the `?n=xxxx' to match how many containers you have.
Next is a way to automatically remove old and unused containers.
This threads dates back a long time, the most recents tools that one should consider are skopeo and crane.
skopeo supports signing and has many other features, while crane is a bit more minimalistic and I found it easier to integrate with in a simple shell script.
Docker search registry v2 functionality is currently not supported at the time of this writing. See discussion since Feb 2015: "propose registry search functionality #206" https://github.com/docker/distribution/issues/206
I wrote a script, view-private-registry, that you can find: https://github.com/BradleyA/Search-docker-registry-v2-script.1.0
It is not pretty but it gets the information needed from the private registry.
Example of output from view-private-registry:
$ view-private-registry`
busybox:latest
gcr.io/google_containers/etcd:2.0.9
gcr.io/google_containers/hyperkube:v0.21.2
gcr.io/google_containers/pause:0.8.0
google/cadvisor:latest
jenkins:latest
logstash:latest
mongo:latest
nginx:latest
python:2.7
redis:latest
registry:2.1.1
stackengine/controller:latest
tomcat:7
tomcat:latest
ubuntu:14.04.2
Number of images: 16
Disk space used: 1.7G /mnt/three/docker-registry/registry-data
One liner bash to list all images with their tags:
curl --user user:pass https://myregistry.com/v2/_catalog | jq .repositories | sed -n 's/[ ",]//gp' | xargs -L1 -IIMAGE curl -s --user user:pass https://myregistry.com/v2/IMAGE/tags/list | jq '. as $parent | .tags[] | $parent.name + ":" + . '
Two lines to search for something in the image name:
search=my_container_part_name
curl --user user:pass https://registry.medworx.io/v2/_catalog | jq .repositories | sed -n '/'"$search"'/{s/[ ",]//gp;}' | xargs -L1 -IIMAGE curl -s --user user:pass https://registry.medworx.io/v2/IMAGE/tags/list | jq '. as $parent | .tags[] | $parent.name + ":" + . '
replace: user, pass and myregistry.com accordingly
uses curl, sed, xargs and jq and is hard to understand... but it does the job. It produces one call per image + 1.
If you can ssh or attach to the docker registry container, just browse the filesystem to look for things you want, like:
kubectl exec -it docker-registry-0 -- /bin/sh
ls /var/lib/registry/docker/registry/v2/repositories
ls /var/lib/registry/docker/registry/v2/repositories/busybox/_manifests/tags/
Since each registry runs as a container the container ID has an associated log file ID-json.log this log file contains the vars.name=[image] and vars.reference=[tag]. A script can be used to extrapolate and print these. This is perhaps one method to list images pushed to registry V2-2.0.1.
If your use-case is identifying only SIGNED and TRUSTED images for production, then this method is handy.
It parses a docker image repo for all SIGNED tags and strips away all the JSON formatting, puking-out only clean image tags. Which of course can be processed further according to your requirements.
Format of Command:
docker trust inspect imageName | grep "SignedTag" | awk -F'"' '{print $4}'
Examples using the nginx & Bitnami Docker repos:
docker trust inspect nginx | grep "SignedTag" | awk -F'"' '{print $4}'
docker trust inspect bitnami/java | grep "SignedTag" | awk -F'"' '{print $4}'
If there are no signed images then No signatures or cannot access imageName will be returned.
Example of a repo WITHOUT signed images (at the time of this writing) using the Wordpress Docker repo:
docker trust inspect wordpress | grep "SignedTag" | awk -F'"' '{print $4}'
If you want a nice web interface to your registry you can use this registry-browser docker image. This is useful if you just want to look around your registry, different repositories and tags.
If, the accepted answer here only returns a blank line, it is likely because of your ssl/tls cert on your registry server. Use the --insecure flag:
curl --insecure https://<registryHostnameOrIP>:5000/v2/_catalog

Deis docker image deploy

Trying to deploy the go-example app from the documentation :
http://docs.deis.io/en/latest/using_deis/using-docker-images/#using-docker-images
I am skipping the "Prepare the application" bit and trying to deploy the example docker app gabrtv/example-go
I run the following to do the deployment :
deis pull gabrtv/example-go:latest
Does not work I get the following :
"GET Image Error (404: {\"error\": \"Tag not found\"})"
Looking at
https://registry.hub.docker.com/u/gabrtv/example-go/tags/manage/
The latest tag is there.
Pulling it with
docker pull gabrtv/example-go
it get's pulled correctly. So I am not really sure what I am doing wrong.
Using the controller API with curl gives me the same result :
curl -i -X POST \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d '{"image":"gabrtv/example-go"}' \
http://$IP:$PORT/v1/apps/dummyapp2/builds/
Anyone have any idea?
Are you also skipping the section 'Create an Application'? In Deis an application is a group of container being load balanced to by the routing layer. In the example they have you create a folder named 'example-go', cd into it, and then run 'deis create'. This defaults to the current folders name for the application name. Instead you can run:
deis create example-go
Then you can run the deis pull command with the '-a' flag telling it which application to to associate the container with.
deis pull gabrtv/example-go:latest -a example-go

Resources