Last active
February 3, 2022 08:51
-
-
Save ttys3/6c3ac108e55e434842cd9797e13ffc15 to your computer and use it in GitHub Desktop.
create a podman container with fifo named pipe as log file
This file contains 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/sh | |
# create a podman container with fifo named pipe as log file | |
# for demonstrate issue https://github.com/containers/podman/issues/13081 | |
CTR_NAME="redis-demo" | |
function print_title() { | |
title=$1 | |
echo "" | |
echo "|=================== $title ===================>>>" | |
echo "" | |
} | |
print_title "remove container first, name=$CTR_NAME" | |
sudo podman rm -f $CTR_NAME | |
sudo test -d /var/lib/containers/ || sudo mkdir -p /var/lib/containers/ | |
sudo rm /var/lib/containers/redis-demo.fifo | |
sudo mkfifo /var/lib/containers/redis-demo.fifo | |
sudo ls -lh /var/lib/containers/redis-demo.fifo | |
print_title "begin POST /v1.0.0/libpod/containers/create" | |
PODMAN_API_CALL='sudo curl --max-time 60 -sSf --unix-socket /run/podman/podman.sock' | |
CTR_ID=$($PODMAN_API_CALL -X POST http://d/v1.0.0/libpod/containers/create -H 'Content-Type: application/json' -d '{ "name": "redis-demo", "log_configuration": { "driver": "k8s-file", "path": "/var/lib/containers/redis-demo.fifo" }, "env": { "foo": "bar" }, "pidns": {}, "utsns": {}, "image": "redis:6.2.6", "mounts": [], "ipcns": {}, "netns": {}, "portmappings": [], "dns_server": [ "8.8.8.8" ], "resource_limits": { "memory": { "limit": 314572800 }, "cpu": { "shares": 100 } }, "cgroupns": {} }' | jq -r '.Id') | |
if [[ "x$CTR_ID" = "x" ]]; then | |
echo "failed to create container" | |
exit -1 | |
else | |
echo "container created, id=$CTR_ID" | |
sudo podman inspect $CTR_NAME | |
fi |
This file contains 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/sh | |
# try start a podman container which been created with fifo named pipe as log file | |
# for demonstrate issue https://github.com/containers/podman/issues/13081 | |
CTR_NAME="redis-demo" | |
function print_title() { | |
title=$1 | |
now_date=$(date '+%Y-%m-%d %T') | |
echo "" | |
echo "" | |
echo "$now_date |=================== $title ===================>>>" | |
echo "" | |
} | |
function podman_api_call() { | |
method=$1 | |
api=$2 | |
verbose=${3:-true} | |
data=${4:-"{}"} | |
curl_param="-sSf" | |
if [[ $verbose = "true" ]]; then | |
curl_param="-D -" | |
fi | |
data_param='' | |
if [[ "$method" = "POST" ]] && [[ "$data" != "{}" ]]; then | |
data_param="-H 'Content-Type: application/json' -d $data" | |
fi | |
print_title "begin $method $api $data_param" | |
sudo curl --max-time 60 $curl_param --unix-socket /run/podman/podman.sock -X $method http://d$api $data_param | |
} | |
CTR_ID=$(sudo podman inspect --format "{{.Id}}" redis-demo) | |
if [[ "x$CTR_ID" = "x" ]]; then | |
echo "failed to find container id by name" | |
exit -1 | |
else | |
echo "exists container found, id=$CTR_ID" | |
fi | |
#podman_api_call DELETE /v1.0.0/libpod/containers/$CTR_NAME?force=true&v=true | |
podman_api_call POST /v1.0.0/libpod/containers/$CTR_ID/start | |
if [[ $? -ne 0 ]]; then | |
echo "start container failed, timeout is 60s" | |
echo "now there is one conmon process got stuck forever..." | |
ps aux | grep -i conmon | grep -i $CTR_ID | |
exit $? | |
fi | |
podman_api_call POST "/v1.0.0/libpod/containers/$CTR_ID/wait?condition=running&condition=exited" | |
podman_api_call GET /v1.0.0/libpod/containers/$CTR_ID/json | |
podman_api_call GET "/v1.0.0/libpod/containers/$CTR_ID/stats?stream=false" | |
print_title "check container status" | |
sudo podman ps | grep $CTR_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment