Docker image with curl
As you may know, curl
comprises two components: the library with the same name and a dynamically linked executable
file. When using curl
in Docker images based on scratch
(empty file system), we have two options:
- Include all required libraries for
curl
in the image. - Compile
curl
as a static binary.
This repository contains a Dockerfile using the second approach (the main idea was found here).
Important note: Some
curl
features (such asgopher
,imap
,proxy
, and others) have been disabled for binary file size reasons.
Another important change is that when the --fail
flag is used, the exit code on error is 1 (instead of 22). You
can find more details about the patch here. This change was made for use in Docker
health checks (the possible exit codes for Docker health checks are: 0 for success, indicating the container is
healthy and ready for use, and 1 for unhealthy, indicating the container is not working correctly):
$ docker run --rm tarampampam/curl -s --fail --show-error https://httpbin.org/status/401
curl: (22) The requested URL returned error: 401
$ echo "Exit code: $?"
Exit code: 1
Registry | Image |
---|---|
GitHub Container Registry | ghcr.io/tarampampam/curl |
Docker Hub | tarampampam/curl |
Images, based on the
alpine
image has a postfix-alpine
in the tag name, e.g.:tarampampam/curl:8.0.1-alpine
.
Following platforms for this image are available:
$ docker run --rm mplatform/mquery tarampampam/curl:latest
Image: tarampampam/curl:latest
* Manifest List: Yes (Image type: application/vnd.docker.distribution.manifest.list.v2+json)
* Supported platforms:
- linux/amd64
- linux/386
- linux/arm64
- linux/arm/v6
- linux/arm/v7
For example - as a docker healthcheck (note - we use scratch
as a base):
# use empty filesystem
FROM scratch
# import some executable application
COPY --from=docker.io/containous/whoami:v1.5.0 /whoami /whoami
# import curl from current repository image
COPY --from=ghcr.io/tarampampam/curl:8.6.0 /bin/curl /bin/curl
# Docs: <https://docs.docker.com/engine/reference/builder/#healthcheck>
HEALTHCHECK --interval=5s --timeout=2s --retries=2 --start-period=2s CMD [ \
"curl", "--fail", "http://127.0.0.1:80/" \
]
ENTRYPOINT ["/whoami"]
After that you can build this image, run, and watch the state:
$ docker build --tag healthcheck-test:local .
...
Successfully built 72bf22424af7
Successfully tagged healthcheck-test:local
$ docker run --rm -d --name healthcheck-test healthcheck-test:local
b3f20332ac19b42dfed03021c0b90b3650b9a7efbaea7c8800d35551e43d35d7
$ docker ps --filter 'name=healthcheck-test' --format '{{.Status}}'
Up 1 minutes (healthy)
$ docker kill healthcheck-test
New versions publishing is very simple - just make required changes in this repository and "publish" new release using repo releases page.
Docker images will be build and published automatically.
The new release will overwrite the
latest
andlatest-alpine
docker image tags in both registers.
If you find any package errors, please, make an issue in current repository.
WTFPL. Use anywhere for your pleasure.