Created
September 1, 2021 20:59
-
-
Save robbmanes/b700f2cae8f72bace8955652510136cd to your computer and use it in GitHub Desktop.
Simple script to test compatibility with podman API v2/Docker Engine API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONTAINER_NAME="nginx" | |
ENDPOINT="localhost:8080/v3.0.0" | |
function section { | |
echo "" | |
echo $1 | |
printf -v UNDERLINE "%-${#1}s" '=' | |
echo "${UNDERLINE// /=}" | |
} | |
function main { | |
section "Create a container" | |
read -r -d '' CREATE <<- EOM | |
{ | |
"Image":"docker.io/nginx:latest" | |
} | |
EOM | |
curl -L -w "RC=%{http_code}\n" -H "Content-Type: application/json" -d "${CREATE}" http://$ENDPOINT/containers/create?name=$CONTAINER_NAME | |
section "Start the container" | |
curl -L -w "RC=%{http_code}\n" -X POST http://$ENDPOINT/containers/$CONTAINER_NAME/start | |
section "Inspect the container" | |
curl -L -w "RC=%{http_code}\n" http://$ENDPOINT/containers/$CONTAINER_NAME/json | |
section "Copy a file to the container" | |
touch api-testfile | |
curl -L -w "RC=%{http_code}\n" -X PUT -H "Content-Type: application/x-tar" -d "$(pwd)/api-testfile" http://$ENDPOINT/containers/$CONTAINER_NAME/archive | |
rm -f api-testfile | |
section "Stop the container" | |
curl -L -w "RC=%{http_code}\n" -X POST -H "Content-Type: application/json" http://$ENDPOINT/containers/$CONTAINER_NAME/stop | |
section "Delete the container" | |
curl -L -w "RC=%{http_code}\n" -X DELETE -H "Content-Type: application/json" http://$ENDPOINT/containers/$CONTAINER_NAME | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment