Skip to content

Commit

Permalink
start-localhost-registry: Start container if it already exists
Browse files Browse the repository at this point in the history
Previously an error occurred if the container existed because container
creation tried to use a name already in use.  It's safe to "start" a
container that's already started, so this makes the program idempotent.

This also handles the case of the container existing but being stopped,
which previously wasn't handled.
  • Loading branch information
tsibley committed Jun 23, 2023
1 parent ce72f41 commit bbda96b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SHELL := bash -euo pipefail
.PHONY: local-image test

local-image:
./devel/start-localhost-registry || true
./devel/start-localhost-registry
./devel/build

# Don't pull base-builder image since it's huge and not needed for local
Expand Down
22 changes: 13 additions & 9 deletions devel/start-localhost-registry
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ NAME=nextstrain-local-registry
# Docker image that provides the registry service.
IMAGE=registry:2

docker run \
--detach \
--publish 127.0.0.1:"$PORT":"$PORT" \
--restart always \
--name "$NAME" \
--volume "$DATA":/var/lib/registry \
--user "$(id -u):$(id -g)" \
"$IMAGE" \
> /dev/null
if docker container inspect "$NAME" &>/dev/null; then
docker container start "$NAME"
else
docker run \
--detach \
--publish 127.0.0.1:"$PORT":"$PORT" \
--restart always \
--name "$NAME" \
--volume "$DATA":/var/lib/registry \
--user "$(id -u):$(id -g)" \
"$IMAGE" \
> /dev/null
fi

0 comments on commit bbda96b

Please sign in to comment.