-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstart.sh
executable file
·44 lines (36 loc) · 1.66 KB
/
start.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Configuration values
IMAGE_NAME="yolov8_docker" # Set the docker image name
IMAGE_TAG="1.0.0" # Set the docker image tag
FULL_IMAGE_NAME="${IMAGE_NAME}:${IMAGE_TAG}"
WORKING_DIR="/home/app"
LOCAL_INFERENCE_RESULTS_DIR="/path/to/local/inference/results" # Set the local inference results directory
LOCAL_DATA_DIR="/path/to/local/data" # Set the local data directory
DOCKER_INFERENCE_RESULTS_DIR="${WORKING_DIR}/runs"
DOCKER_DATA_DIR="${WORKING_DIR}/data"
# Stop and remove any previous containers running from the given image
echo "Stopping and removing any existing containers for the image ${FULL_IMAGE_NAME}..."
CONTAINER_IDS=$(docker ps -a -q --filter ancestor=${FULL_IMAGE_NAME})
if [ -n "$CONTAINER_IDS" ]; then
docker stop $CONTAINER_IDS
docker rm $CONTAINER_IDS
echo "Stopped and removed containers: $CONTAINER_IDS"
else
echo "No containers found for image ${FULL_IMAGE_NAME}."
fi
# Remove the previous Docker image if it exists
echo "Removing the Docker image ${FULL_IMAGE_NAME} if it exists..."
IMAGE_IDS=$(docker images -q ${FULL_IMAGE_NAME})
if [ -n "$IMAGE_IDS" ]; then
docker rmi $IMAGE_IDS
echo "Removed image: $IMAGE_IDS"
else
echo "No image found with the name ${FULL_IMAGE_NAME}."
fi
# Build the docker image from the Dockerfile
echo "Building the Docker image ${FULL_IMAGE_NAME}..."
docker build -t ${FULL_IMAGE_NAME} .
# Run the docker image
echo "Running the Docker image ${FULL_IMAGE_NAME}..."
docker run -d --ipc=host --gpus all -p 8080:8080 -v $LOCAL_INFERENCE_RESULTS_DIR:$DOCKER_INFERENCE_RESULTS_DIR -v $LOCAL_DATA_DIR:$DOCKER_DATA_DIR ${FULL_IMAGE_NAME}
echo "Docker container is up and running."