forked from ItoMasaki/ROS2Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RUN-DOCKER-CONTAINER.bash
executable file
·58 lines (43 loc) · 2.18 KB
/
RUN-DOCKER-CONTAINER.bash
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
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# This script runs a Docker container instance with a name based on [docker-project].
#
# Usage: bash RUN-DOCKER-CONTAINER.bash [docker-project] [ros-launch]
#
# [docker-project]: Used to name the Docker container and create multiple instances if needed. Default value is '$USER'.
# [ros-launch]: Used to automatically preload a ROS launch file when entering the Docker container for convenience. Format is 'filename.launch'.
#################################################################################
# Set the default Docker runtime to use in './docker/docker-compose.yml'.
if [ -e /proc/driver/nvidia/version ]; then
export DOCKER_RUNTIME=nvidia
else
export DOCKER_RUNTIME=runc
fi
################################################################################
# Set the Docker container name from the [docker-project] argument.
# If no [docker-project] is given, use the current user name as the Docker project name.
# DOCKER_PROJECT=$1
if [ -z "${DOCKER_PROJECT}" ]; then
DOCKER_PROJECT=${USER}
fi
KEYWORD="ros2docker"
DOCKER_CONTAINER=$(docker ps -a --format "{{.Names}}" | grep "$KEYWORD")
if [ -z "${DOCKER_CONTAINER}" ]; then
DOCKER_CONTAINER=${USER}
# Run the Docker container in the background.
# Any changes made to './docker/docker-compose.yml' will recreate and overwrite the container.
docker-compose -p ${DOCKER_CONTAINER} -f ./docker/docker-compose.yml up -d
fi
echo "$0: DOCKER_PROJECT=${DOCKER_PROJECT}"
echo "$0: DOCKER_CONTAINER=${DOCKER_CONTAINER}"
DOCKER_CONTAINER=$(docker ps -a --format "{{.Names}}" | grep "$KEYWORD")
################################################################################
# Display GUIs through X Server by granting full access to any external client.
xhost +
################################################################################
echo ${DOCKER_PROJECT}
# Run docker container
if [ ! $1 ]; then
docker exec -i -t ${DOCKER_CONTAINER} bash
else
docker exec -i -t ${DOCKER_CONTAINER} bash -i -c "source ~/ROS2Docker/docker/ros2-devel/scripts/run-roslaunch-repeatedly.bash $1"
fi