I am trying to write a shell script that should start a docker container.
I have a running example, but it uses /bin/bash
:
#!/bin/bash
export NETWORK=jetty-svc-test
export IMAGE_TAG=jetty-test-app
export SVC_NAME=svc-test
clean_up() {
docker stop $SVC_NAME
docker network rm $NETWORK
}
docker network create $NETWORK
if [ $? -eq 1 ]; then
exit 1
fi
docker build --tag $IMAGE_TAG .
if [ $? -eq 1 ]; then
exit 1
fi
docker run -it --rm --name $SVC_NAME --network=$NETWORK -v $(pwd)/app:/app -d $IMAGE_TAG
if [ $? -eq 1 ]; then
exit 1
fi
sleep 5
export RES=$(docker run --rm --network=$NETWORK curlimages/curl:7.71.1 http://$SVC_NAME:8080 | docker run --rm -i stedolan/jq .)
export HEALTH_CHECK=$(echo "$RES" | docker run --rm -i stedolan/jq -r .status)
if [ "$HEALTH_CHECK" != "I am healthy" ]; then
clean_up
exit 1
fi
clean_up
but I need it in #!/bin/sh
. For instance, the statement export RES=$(..
does not work in #!/bin/sh
.
I need to rewrite the script above, because https://hub.docker.com/layers/docker/library/docker/19.03.12/images/sha256-d208a88b6afa09430a2f4becbc8dbe10bfdaeb1703f9ff3707ca96e89358a8e4?context=explore only supports #!/bin/sh
and I would like to run the script above inside the docker:dind container.
How to write docker command with /bin/sh and assign result to variable?