File size: 1,079 Bytes
a220803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
#!/usr/bin/env bash

WORK_DIR=$(dirname "$(readlink -f "$0")")
source $WORK_DIR/setup_env.sh

RUNNING_IDS="$(docker ps --filter ancestor=$TAG --format "{{.ID}}")"

if [ -n "$RUNNING_IDS" ]; then
    # Initialize an array to hold the container IDs
    declare -a container_ids=($RUNNING_IDS)

    # Get the first container ID using array indexing
    ID=${container_ids[0]}

    # Print the first container ID
    echo ' '
    echo "The running container ID is: $ID, enter it!"
else
    echo ' '
    echo "Not found running containers, run it!"

    # Run a new docker container instance
    ID=$(docker run \
        --rm \
        --gpus all \
        -itd \
        --ipc=host \
        --ulimit memlock=-1 \
        --ulimit stack=67108864 \
        -e DISPLAY=$DISPLAY \
        -v /tmp/.X11-unix/:/tmp/.X11-unix/ \
        -v $PWD:/home/$USER_NAME/workspace \
        -w /home/$USER_NAME/workspace \
        $(cat $WORK_DIR/ports.txt) \
        $TAG)
fi

docker logs $ID

echo ' '
echo ' '
echo '========================================='
echo ' '

docker exec -it $ID bash