Skip to content

Instantly share code, notes, and snippets.

@robbmanes
Created September 1, 2021 20:59
Show Gist options
  • Save robbmanes/b700f2cae8f72bace8955652510136cd to your computer and use it in GitHub Desktop.
Save robbmanes/b700f2cae8f72bace8955652510136cd to your computer and use it in GitHub Desktop.
Simple script to test compatibility with podman API v2/Docker Engine API
#!/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