Skip to content

Commit

Permalink
Use docker container inspect
Browse files Browse the repository at this point in the history
docker inspect may also return image information, which is not desired.
  • Loading branch information
michaelsauter committed Mar 8, 2024
1 parent 96632a0 commit 125ae1e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions scripts/kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ reg_ip_selector='{{.NetworkSettings.Networks.kind.IPAddress}}'
reg_network='kind'

# create registry container unless it already exists
running="$(docker inspect -f '{{.State.Running}}' "${registry_name}" 2>/dev/null || true)"
running="$(docker container inspect -f '{{.State.Running}}' "${registry_name}" 2>/dev/null || true)"

# If the registry already exists, but is in the wrong network, we have to
# re-create it.
if [ "${running}" = 'true' ]; then
reg_ip="$(docker inspect -f ${reg_ip_selector} "${registry_name}")"
reg_ip="$(docker container inspect -f ${reg_ip_selector} "${registry_name}")"
if [ "${reg_ip}" = '' ]; then
docker kill "${registry_name}"
docker rm "${registry_name}"
Expand All @@ -73,15 +73,15 @@ if [ "${running}" != 'true' ]; then
if [ "${net_driver}" != "bridge" ]; then
docker network create "${reg_network}"
fi
if docker inspect "${registry_name}" >/dev/null 2>&1; then
if docker container inspect "${registry_name}" >/dev/null 2>&1; then
docker rm "${registry_name}"
fi
docker run \
-d --restart=always -p "${registry_port}:5000" --name "${registry_name}" --net "${reg_network}" \
registry:2
fi

reg_ip="$(docker inspect -f ${reg_ip_selector} "${registry_name}")"
reg_ip="$(docker container inspect -f ${reg_ip_selector} "${registry_name}")"
if [ "${reg_ip}" = "" ]; then
echo "Error creating registry: no IPAddress found at: ${reg_ip_selector}"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-bitbucket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ while [ "$#" -gt 0 ]; do
esac; shift; done

if [ "${reuse}" = "true" ]; then
if ! docker inspect ${BITBUCKET_SERVER_CONTAINER_NAME} &> /dev/null; then
if ! docker container inspect ${BITBUCKET_SERVER_CONTAINER_NAME} &> /dev/null; then
echo "No existing Bitbucket container ${BITBUCKET_SERVER_CONTAINER_NAME} found ..."
else
echo "Reusing existing Bitbucket container ${BITBUCKET_SERVER_CONTAINER_NAME} ..."
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-nexus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ while [ "$#" -gt 0 ]; do
esac; shift; done

if [ "${reuse}" = "true" ]; then
if ! docker inspect ${CONTAINER_NAME} &> /dev/null; then
if ! docker container inspect ${CONTAINER_NAME} &> /dev/null; then
echo "No existing Nexus container ${CONTAINER_NAME} found ..."
else
echo "Reusing existing Nexus container ${CONTAINER_NAME} ..."
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-sonarqube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ while [ "$#" -gt 0 ]; do
esac; shift; done

if [ "${reuse}" = "true" ]; then
if [ "$(docker inspect ${CONTAINER_NAME} -f '{{.State.Running}}')" = "true" ]; then
if [ "$(docker container inspect ${CONTAINER_NAME} -f '{{.State.Running}}')" = "true" ]; then
echo "Reusing running SonarQube container ${CONTAINER_NAME} ..."
exit 0
else
Expand Down

0 comments on commit 125ae1e

Please sign in to comment.