forked from lAmeR1/kaspa-db-filler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_run.sh
30 lines (24 loc) · 938 Bytes
/
build_run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Set variables
CONTAINER_NAME="htn-db-filler"
IMAGE_NAME="htn-db-filler"
TAG="latest"
# Check if a container with the specified name already exists
container_id=$(docker ps -aq -f "name=$CONTAINER_NAME")
# If the container exists, stop and remove it
if [ -n "$container_id" ]; then
echo "Stopping and removing existing container: $container_id"
docker stop "$container_id"
docker rm "$container_id"
else
echo "No existing container found with name: $CONTAINER_NAME"
fi
# Build the Docker image
echo "Building image: $IMAGE_NAME:$TAG"
docker build -t "$IMAGE_NAME:$TAG" .
# Run the container from the new image
echo "Running new container: $CONTAINER_NAME"
docker run --network host --restart unless-stopped --name "$CONTAINER_NAME" -d "$IMAGE_NAME:$TAG"
# Check if a container with the specified name already exists
container_id=$(docker ps -aq -f "name=$CONTAINER_NAME")
docker logs -f "$container_id"