Skip to content

Commit

Permalink
Docker: create named docker volumes from images instead of unnamed vo…
Browse files Browse the repository at this point in the history
…lumes from --volumes-from

* create a proper volume instead of creating intermediate container from image
  and then using --volumes-from
* running dev or runtime apollo container leaves a bunch of unnamed volumes:
  $ docker volume ls
  DRIVER    VOLUME NAME
  local     5c20d4ed0f6a2dfca8cba1e182d8e74327d409be50925156e6ae35b8a803547d
  local     8a3105c9c0d613512f73c3b3fdb6117b55051f69a58b7daa05979a6587fd18ea
  local     8ce888434e441d9d68775be6bf962d6950fb4f6590aea6deb29d622b5c4f3958
  local     55c7ad8291648fd446b3cdab389361f81e214c66c5295d84a5499abed6b8fd00
  local     0715f504c2745f85a0c5b1d6cc983395da93f8fe7bca5f066f4265421656d557
  local     0757b2c39394975b5e5ecc2edc6da4c03ff2747fc15eb373dc7754d6f58dcb06
  local     0348328d88b9c15fc153045ebd291f067688f9f6fe9f2c71dfe76c9651543ee4
  local     430718d15fa688cbfd42099c7f8886e8b1246dafd11ae56a1b65a54bffe77a5f
  local     a41b4a8ba3b4eba78393224635f657f01b71d20994c5c4293262b07f1cdec8d3
  local     aa2874fe10829f7e12017616657f8eee2d916b1118eb3bb7469460e4dcb1c6c0
  local     aace6d89958015ea610445760b6d5d90b4930398eb2d58ad405aa0a580b915e1
  local     cfc3394ea18bc356e429089269c6b04df2ca800056b030195c02b3db29bafdb7
  local     e9d4100f63d28d9b519312a8b024d5102271b006278bca79b1a23d6b1a145cbd
  local     ebecb4233da0c79fb193ab244a371606fdc2922645aa117d88ecd7a2e0271087
  local     edf30ff61831825429177a12720798c394d37338e259a9f46eb5583de6531daf
  local     f2ad70033de87dd370291000258ad4108e582142250406157458f1ccc5115fa2
  ...
  which even docker inspect doesn't really help to identify what they are and
  what container is using these

  possibly the easies way to find out what is using them is to try to remove
  them which shows an error listing the containers which use them:
  $ docker volume rm f2ad70033de87dd370291000258ad4108e582142250406157458f1ccc5115fa2
  Error response from daemon: remove f2ad70033de87dd370291000258ad4108e582142250406157458f1ccc5115fa2: volume is in use - [f376385ab7155ba5ccc389a4289e6c56ebda317ecaf3bf4bd0894e1b9129ab52, 3d33606654fc2046582a925688da206a75fd45fca76529988f38cec8396b0900]

  $ docker inspect f376385ab7155ba5ccc389a4289e6c56ebda317ecaf3bf4bd0894e1b9129ab52 |grep Image.*apollo
    "Image": "apolloauto/apollo:map_volume-sunnyvale_big_loop-latest",
  $ docker inspect 3d33606654fc2046582a925688da206a75fd45fca76529988f38cec8396b0900 |grep Image.*apollo
    "Image": "apolloauto/apollo:runtime-x86_64-18.04-20210202_1232",

  create a volumes as described in:
  https://stackoverflow.com/questions/38700606/how-to-create-data-volume-from-image-for-use-in-nginx-container
  the only disadvantage is that now the script needs to know the mount path
  for these volumes, but for maps it's easy and for other volumes it doesn't seem to change

* after this change the volumes have names:
  $ docker volume ls
  DRIVER    VOLUME NAME
  local     apollo_audio_volume_martin
  local     apollo_faster_rcnn_volume_martin
  local     apollo_map_volume-san_mateo_martin
  local     apollo_map_volume-sunnyvale_big_loop_martin
  local     apollo_map_volume-sunnyvale_loop_martin
  local     apollo_map_volume-sunnyvale_with_two_offices_martin
  local     apollo_smoke_volume_martin
  local     apollo_yolov4_volume_martin

  and there is only one container running:
  $ docker container ls
  CONTAINER ID   IMAGE                                              COMMAND       CREATED          STATUS          PORTS     NAMES
  d3b24c9e99ab   apolloauto/apollo:dev-x86_64-18.04-20210204_2153   "/bin/bash"   44 seconds ago   Up 43 seconds             apollo_dev_martin

Signed-off-by: Martin Jansa <[email protected]>
  • Loading branch information
shr-project authored and storypku committed Mar 15, 2021
1 parent 61f8868 commit 8744690
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
35 changes: 21 additions & 14 deletions docker/scripts/dev_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,21 @@ function docker_pull() {
}

function docker_restart_volume() {
local container="$1"
local volume="$1"
local image="$2"
info "Restart volume ${container} from image: ${image}"
docker stop "${container}" &>/dev/null
local path="$3"
info "Create volume ${volume} from image: ${image}"
docker_pull "${image}"
docker run -itd --rm --name "${container}" "${image}"
docker volume rm "${volume}" >/dev/null 2>&1
docker run -v "${volume}":"${path}" --rm "${image}" true
}

function restart_map_volume_if_needed() {
local map_name="$1"
local map_version="$2"
local map_volume="apollo_map_volume-${map_name}_${USER}"
local map_path="/apollo/modules/map/data/${map_name}"

if [[ ${MAP_VOLUMES_CONF} == *"${map_volume}"* ]]; then
info "Map ${map_name} has already been included."
else
Expand All @@ -271,8 +274,8 @@ function restart_map_volume_if_needed() {
fi
info "Load map ${map_name} from image: ${map_image}"

docker_restart_volume "${map_volume}" "${map_image}"
MAP_VOLUMES_CONF="${MAP_VOLUMES_CONF} --volumes-from ${map_volume}"
docker_restart_volume "${map_volume}" "${map_image}" "${map_path}"
MAP_VOLUMES_CONF="${MAP_VOLUMES_CONF} --volume ${map_volume}:${map_path}"
fi
}

Expand Down Expand Up @@ -302,27 +305,31 @@ function mount_other_volumes() {
# AUDIO
local audio_volume="apollo_audio_volume_${USER}"
local audio_image="${DOCKER_REPO}:data_volume-audio_model-${TARGET_ARCH}-latest"
docker_restart_volume "${audio_volume}" "${audio_image}"
volume_conf="${volume_conf} --volumes-from ${audio_volume}"
local audio_path="/apollo/modules/audio/data/"
docker_restart_volume "${audio_volume}" "${audio_image}" "${audio_path}"
volume_conf="${volume_conf} --volume ${audio_volume}:${audio_path}"

# YOLOV4
local yolov4_volume="apollo_yolov4_volume_${USER}"
local yolov4_image="${DOCKER_REPO}:yolov4_volume-emergency_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${yolov4_volume}" "${yolov4_image}"
volume_conf="${volume_conf} --volumes-from ${yolov4_volume}"
local yolov4_path="/apollo/modules/perception/camera/lib/obstacle/detector/yolov4/model/"
docker_restart_volume "${yolov4_volume}" "${yolov4_image}" "${yolov4_path}"
volume_conf="${volume_conf} --volume ${yolov4_volume}:${yolov4_path}"

# FASTER_RCNN
local faster_rcnn_volume="apollo_faster_rcnn_volume_${USER}"
local faster_rcnn_image="${DOCKER_REPO}:faster_rcnn_volume-traffic_light_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${faster_rcnn_volume}" "${faster_rcnn_image}"
volume_conf="${volume_conf} --volumes-from ${faster_rcnn_volume}"
local faster_rcnn_path="/apollo/modules/perception/production/data/perception/camera/models/traffic_light_detection/faster_rcnn_model"
docker_restart_volume "${faster_rcnn_volume}" "${faster_rcnn_image}" "${faster_rcnn_path}"
volume_conf="${volume_conf} --volume ${faster_rcnn_volume}:${faster_rcnn_path}"

# SMOKE
if [[ "${TARGET_ARCH}" == "x86_64" ]]; then
local smoke_volume="apollo_smoke_volume_${USER}"
local smoke_image="${DOCKER_REPO}:smoke_volume-yolo_obstacle_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${smoke_volume}" "${smoke_image}"
volume_conf="${volume_conf} --volumes-from ${smoke_volume}"
local smoke_path="/apollo/modules/perception/production/data/perception/camera/models/yolo_obstacle_detector/smoke_libtorch_model"
docker_restart_volume "${smoke_volume}" "${smoke_image}" "${smoke_path}"
volume_conf="${volume_conf} --volume ${smoke_volume}:${smoke_path}"
fi

OTHER_VOLUMES_CONF="${volume_conf}"
Expand Down
35 changes: 21 additions & 14 deletions docker/scripts/runtime_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,21 @@ function docker_pull() {
}

function docker_restart_volume() {
local container="$1"
local volume="$1"
local image="$2"
info "Restart volume ${container} from image: ${image}"
docker stop "${container}" &>/dev/null
local path="$3"
info "Create volume ${volume} from image: ${image}"
docker_pull "${image}"
docker run -itd --rm --name "${container}" "${image}"
docker volume rm "${volume}" >/dev/null 2>&1
docker run -v "${volume}":"${path}" --rm "${image}" true
}

function restart_map_volume_if_needed() {
local map_name="$1"
local map_version="$2"
local map_volume="apollo_map_volume-${map_name}_${USER}"
local map_path="/apollo/modules/map/data/${map_name}"

if [[ ${MAP_VOLUMES_CONF} == *"${map_volume}"* ]]; then
info "Map ${map_name} has already been included."
else
Expand All @@ -228,8 +231,8 @@ function restart_map_volume_if_needed() {
fi
info "Load map ${map_name} from image: ${map_image}"

docker_restart_volume "${map_volume}" "${map_image}"
MAP_VOLUMES_CONF="${MAP_VOLUMES_CONF} --volumes-from ${map_volume}"
docker_restart_volume "${map_volume}" "${map_image}" "${map_path}"
MAP_VOLUMES_CONF="${MAP_VOLUMES_CONF} --volume ${map_volume}:${map_path}"
fi
}

Expand Down Expand Up @@ -259,27 +262,31 @@ function mount_other_volumes() {
# AUDIO
local audio_volume="apollo_audio_volume_${USER}"
local audio_image="${DOCKER_REPO}:data_volume-audio_model-${TARGET_ARCH}-latest"
docker_restart_volume "${audio_volume}" "${audio_image}"
volume_conf="${volume_conf} --volumes-from ${audio_volume}"
local audio_path="/apollo/modules/audio/data/"
docker_restart_volume "${audio_volume}" "${audio_image}" "${audio_path}"
volume_conf="${volume_conf} --volume ${audio_volume}:${audio_path}"

# YOLOV4
local yolov4_volume="apollo_yolov4_volume_${USER}"
local yolov4_image="${DOCKER_REPO}:yolov4_volume-emergency_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${yolov4_volume}" "${yolov4_image}"
volume_conf="${volume_conf} --volumes-from ${yolov4_volume}"
local yolov4_path="/apollo/modules/perception/camera/lib/obstacle/detector/yolov4/model/"
docker_restart_volume "${yolov4_volume}" "${yolov4_image}" "${yolov4_path}"
volume_conf="${volume_conf} --volume ${yolov4_volume}:${yolov4_path}"

# FASTER_RCNN
local faster_rcnn_volume="apollo_faster_rcnn_volume_${USER}"
local faster_rcnn_image="${DOCKER_REPO}:faster_rcnn_volume-traffic_light_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${faster_rcnn_volume}" "${faster_rcnn_image}"
volume_conf="${volume_conf} --volumes-from ${faster_rcnn_volume}"
local faster_rcnn_path="/apollo/modules/perception/production/data/perception/camera/models/traffic_light_detection/faster_rcnn_model"
docker_restart_volume "${faster_rcnn_volume}" "${faster_rcnn_image}" "${faster_rcnn_path}"
volume_conf="${volume_conf} --volume ${faster_rcnn_volume}:${faster_rcnn_path}"

# SMOKE
if [[ "${TARGET_ARCH}" == "x86_64" ]]; then
local smoke_volume="apollo_smoke_volume_${USER}"
local smoke_image="${DOCKER_REPO}:smoke_volume-yolo_obstacle_detection_model-${TARGET_ARCH}-latest"
docker_restart_volume "${smoke_volume}" "${smoke_image}"
volume_conf="${volume_conf} --volumes-from ${smoke_volume}"
local smoke_path="/apollo/modules/perception/production/data/perception/camera/models/yolo_obstacle_detector/smoke_libtorch_model"
docker_restart_volume "${smoke_volume}" "${smoke_image}" "${smoke_path}"
volume_conf="${volume_conf} --volume ${smoke_volume}:${smoke_path}"
fi

OTHER_VOLUMES_CONF="${volume_conf}"
Expand Down

0 comments on commit 8744690

Please sign in to comment.