Skip to content

Commit

Permalink
Fixes repeated Docker container names (#481)
Browse files Browse the repository at this point in the history
# Description

As of [docker compose
2.24.7](https://docs.docker.com/compose/release-notes/#2247), using the
same name between containers is disallowed even if the profiles that
launch them are mutually exclusive.

This PR alters `docker-compose.yaml` such that containers will now be
appended with their image extension (orbit-base, orbit-ros2). I've also
added `resolve_image_extension` to the logic in `./container.sh` in
order to handle the image_extension arguments.

Fixes Public[
#325](#325)

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have run all the tests with `./orbit.sh --test` and they pass
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->

---------

Signed-off-by: Hunter Hansen <[email protected]>
Co-authored-by: James Smith <[email protected]>
  • Loading branch information
2 people authored and Mayankm96 committed Mar 28, 2024
1 parent 0fc38de commit 0865cf6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 52 deletions.
2 changes: 1 addition & 1 deletion docker/cluster/run_singularity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ setup_directories() {
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# load variables to set the orbit path on the cluster
source $SCRIPT_DIR/../.env
source $SCRIPT_DIR/../.env.base

# make sure that all directories exists in cache directory
setup_directories
Expand Down
83 changes: 47 additions & 36 deletions docker/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,38 @@ check_docker_version() {
fi
}

# Produces container_profile, add_profiles, and add_envs from the image_extension arg
resolve_image_extension() {
# If no profile was passed, we default to 'base'
container_profile=${1:-"base"}

# We also default to 'base' if "orbit" is passed
if [ "$1" == "orbit" ]; then
container_profile="base"
fi

add_profiles="--profile $container_profile"
# We will need .env.base regardless of profile
add_envs="--env-file .env.base"
# The second argument is interpreted as the profile to use.
# We will select the base profile by default.
# This will also determine the .env file that is loaded
if [ "$container_profile" != "base" ]; then
# We have to load multiple .env files here in order to combine
# them for the args from base required for extensions, (i.e. DOCKER_USER_HOME)
add_envs="$add_envs --env-file .env.$container_profile"
fi
}

# Prints a warning message and exits if the passed container is not running
is_container_running() {
container_name="$1"
if [ "$( docker container inspect -f '{{.State.Status}}' $container_name 2> /dev/null)" != "running" ]; then
echo "[Error] The '$container_name' container is not running!" >&2;
exit 1
fi
}

#==
# Main
#==
Expand All @@ -79,24 +111,12 @@ fi

# parse arguments
mode="$1"
resolve_image_extension $2
# resolve mode
case $mode in
start)
echo "[INFO] Building the docker image and starting the container in the background..."
echo "[INFO] Building the docker image and starting the container orbit-$container_profile in the background..."
pushd ${SCRIPT_DIR} > /dev/null 2>&1
# The second argument is interpreted as the profile to use.
# We will select the base profile by default.
# This will also determine the .env file that is loaded
if [ -z "$2" ]; then
add_profiles="--profile base"
add_envs="--env-file .env.base"
else
profile="$2"
add_profiles="--profile $profile"
# We have to load multiple .env files here in order to combine
# them for the args from base required for extensions, (i.e. DOCKER_USER_HOME)
add_envs="--env-file .env.base --env-file .env.$profile"
fi
# We have to build the base image as a separate step,
# in case we are building a profile which depends
# upon
Expand All @@ -105,18 +125,17 @@ case $mode in
popd > /dev/null 2>&1
;;
enter)
echo "[INFO] Entering the existing 'orbit' container in a bash session..."
# Check that desired container is running, exit if it isn't
is_container_running orbit-$container_profile
echo "[INFO] Entering the existing 'orbit-$container_profile' container in a bash session..."
pushd ${SCRIPT_DIR} > /dev/null 2>&1
docker exec --interactive --tty orbit bash
docker exec --interactive --tty orbit-$container_profile bash
popd > /dev/null 2>&1
;;
copy)
# check if the container is running
if [ "$( docker container inspect -f '{{.State.Status}}' orbit 2> /dev/null)" != "running" ]; then
echo "[Error] The 'orbit' container is not running! It must be running to copy files from it." >&2;
exit 1
fi
echo "[INFO] Copying artifacts from the 'orbit' container..."
# Check that desired container is running, exit if it isn't
is_container_running orbit-$container_profile
echo "[INFO] Copying artifacts from the 'orbit-$container_profile' container..."
echo -e "\t - /workspace/orbit/logs -> ${SCRIPT_DIR}/artifacts/logs"
echo -e "\t - /workspace/orbit/docs/_build -> ${SCRIPT_DIR}/artifacts/docs/_build"
echo -e "\t - /workspace/orbit/data_storage -> ${SCRIPT_DIR}/artifacts/data_storage"
Expand All @@ -132,25 +151,17 @@ case $mode in
mkdir -p ./artifacts/docs

# copy the artifacts
docker cp orbit:/workspace/orbit/logs ./artifacts/logs
docker cp orbit:/workspace/orbit/docs/_build ./artifacts/docs/_build
docker cp orbit:/workspace/orbit/data_storage ./artifacts/data_storage
docker cp orbit-$container_profile:/workspace/orbit/logs ./artifacts/logs
docker cp orbit-$container_profile:/workspace/orbit/docs/_build ./artifacts/docs/_build
docker cp orbit-$container_profile:/workspace/orbit/data_storage ./artifacts/data_storage
echo -e "\n[INFO] Finished copying the artifacts from the container."
popd > /dev/null 2>&1
;;
stop)
echo "[INFO] Stopping the launched docker container..."
# Check that desired container is running, exit if it isn't
is_container_running orbit-$container_profile
echo "[INFO] Stopping the launched docker container orbit-$container_profile..."
pushd ${SCRIPT_DIR} > /dev/null 2>&1
if [ -z "$2" ]; then
add_profiles="--profile base"
add_envs="--env-file .env.base"
else
profile="$2"
add_profiles="--profile $profile"
# We have to load multiple .env files here in order to combine
# them for the args from base required for ROS2, (i.e. DOCKER_USER_HOME)
add_envs="--env-file .env.base --env-file .env.$profile"
fi
docker compose --file docker-compose.yaml $add_profiles $add_envs down
popd > /dev/null 2>&1
;;
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ services:
- ISAACSIM_PATH=${DOCKER_ISAACSIM_PATH}
- DOCKER_USER_HOME=${DOCKER_USER_HOME}
image: orbit-base
container_name: orbit
container_name: orbit-base
environment:
# We set DOCKER_ISAACSIM_PATH and then forward it to ISAACSIM_PATH within
# the container to avoid collision with pre-existing ISAACSIM_PATH env vars
Expand Down Expand Up @@ -125,7 +125,7 @@ services:
- ROS2_APT_PACKAGE=${ROS2_APT_PACKAGE:-NONE}
- DOCKER_USER_HOME=${DOCKER_USER_HOME}
image: orbit-ros2
container_name: orbit
container_name: orbit-ros2
environment:
- ISAACSIM_PATH=${DOCKER_ISAACSIM_PATH}
volumes: *default-orbit-volumes
Expand Down
28 changes: 15 additions & 13 deletions docs/source/deployment/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Setup Instructions
Docker and Docker Compose
~~~~~~~~~~~~~~~~~~~~~~~~~

We have tested the container using Docker Engine version 24.0.2 and Docker Compose version 2.18.1.
We have tested the container using Docker Engine version 26.0.0 and Docker Compose version 2.25.0
We recommend using these versions or newer.

* To install Docker, please follow the instructions for your operating system on the `Docker website`_.
* To install Docker Compose, please follow the instructions for your operating system on the `docker-compose`_ page.
* To install Docker Compose, please follow the instructions for your operating system on the `docker compose`_ page.
* Follow the post-installation steps for Docker on the `post-installation steps`_ page. These steps allow you to run
Docker without using ``sudo``.
* To build and run GPU-accelerated containers, you also need install the `NVIDIA Container Toolkit`_.
Expand Down Expand Up @@ -71,11 +71,11 @@ needed to run Orbit inside a Docker container. A subset of these are summarized
* ``Dockerfile.base``: Defines the orbit image by overlaying Orbit dependencies onto the Isaac Sim Docker image.
``Dockerfiles`` which end with something else, (i.e. ``Dockerfile.ros2``) build an `image_extension <#orbit-image-extensions>`_.
* ``docker-compose.yaml``: Creates mounts to allow direct editing of Orbit code from the host machine that runs
the container along with X11 forwarding. It also creates several named volumes such as ``isaac-cache-kit`` to
the container. It also creates several named volumes such as ``isaac-cache-kit`` to
store frequently re-used resources compiled by Isaac Sim, such as shaders, and to retain logs, data, and documents.
* ``base.env``: Stores environment variables required for the ``base`` build process and the container itself. ``.env``
files which end with something else (i.e. ``.env.ros2``) define these for `image_extension <#orbit-image-extensions>`_.
* ``container.sh``: A script that wraps the ``docker-compose`` command to build the image and run the container.
* ``container.sh``: A script that wraps the ``docker compose`` command to build the image and run the container.

Running the Container
---------------------
Expand All @@ -94,32 +94,34 @@ Running the Container
for the ``_build`` subdirectory where build artifacts are stored.


The script ``container.sh`` wraps around three basic ``docker-compose`` commands:
The script ``container.sh`` wraps around three basic ``docker compose`` commands. Each can accept an `image_extension argument <#orbit-image-extensions>`_,
or else they will default to image_extension ``base``:

1. ``start``: This builds the image and brings up the container in detached mode (i.e. in the background). It can accept an
`image_extension argument <#orbit-image-extensions>`_.
1. ``start``: This builds the image and brings up the container in detached mode (i.e. in the background).
2. ``enter``: This begins a new bash process in an existing orbit container, and which can be exited
without bringing down the container. It can accept an `image_extension argument <#orbit-image-extensions>`_.
without bringing down the container.
3. ``copy``: This copies the ``logs``, ``data_storage`` and ``docs/_build`` artifacts, from the ``orbit-logs``, ``orbit-data`` and ``orbit-docs``
volumes respectively, to the ``docker/artifacts`` directory. These artifacts persist between docker
container instances.
container instances and are shared between image extensions.
4. ``stop``: This brings down the container and removes it.

The following shows how to launch the container in a detached state and enter it:

.. code:: bash
# Launch the container in detached mode
# We don't pass an image extension arg, so it defaults to 'base'
./docker/container.sh start
# Enter the container
./docker/container.sh enter
# We pass 'base' explicitly, but if we hadn't it would default to 'base'
./docker/container.sh enter base
To copy files from the container to the host machine, you can use the following command:
To copy files from the base container to the host machine, you can use the following command:

.. code:: bash
# Copy the file /workspace/orbit/logs to the current directory
docker cp orbit:/workspace/orbit/logs .
docker cp orbit-base:/workspace/orbit/logs .
The script ``container.sh`` provides a wrapper around this command to copy the ``logs`` , ``data_storage`` and ``docs/_build``
directories to the ``docker/artifacts`` directory. This is useful for copying the logs, data and documentation:
Expand Down Expand Up @@ -268,7 +270,7 @@ in docker-compose.yaml.
.. _`NVIDIA Omniverse EULA`: https://docs.omniverse.nvidia.com/platform/latest/common/NVIDIA_Omniverse_License_Agreement.html
.. _`container installation`: https://docs.omniverse.nvidia.com/isaacsim/latest/installation/install_container.html
.. _`Docker website`: https://docs.docker.com/desktop/install/linux-install/
.. _`docker-compose`: https://docs.docker.com/compose/install/linux/#install-using-the-repository
.. _`docker compose`: https://docs.docker.com/compose/install/linux/#install-using-the-repository
.. _`NVIDIA Container Toolkit`: https://github.com/NVIDIA/nvidia-container-toolkit
.. _`Container Toolkit website`: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
.. _`post-installation steps`: https://docs.docker.com/engine/install/linux-postinstall/
Expand Down

0 comments on commit 0865cf6

Please sign in to comment.