Skip to content

[Feature] CARLA DevContainer & Docker Improvements – Ubuntu 22.04 #8620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: ue4-dev
Choose a base branch
from

Conversation

wambitz
Copy link

@wambitz wambitz commented Jan 31, 2025

Description

Detailed documentation at: Docs/build_docker_ubuntu22.md

Fixes

  • Update Docker support to Ubuntu 22.04 image
  • Add support for devcontainers

Where has this been tested?

  • Platform(s): Ubuntu 24.04 64 bit (Host) / Ubuntu 22.04 (Docker Image)
  • Python version(s): 3.10
  • Unreal Engine version(s): 4.26

Possible Drawbacks

Backward compatibility with Python 2.7


This change is Reviewable


Summary

This PR introduces two Docker-based approaches for building and running CARLA (version 0.9.15.2) on Ubuntu 22.04 (Jammy):

  1. Monolithic Docker Image – Fully self-contained build with Unreal Engine and CARLA.
  2. Lightweight DevContainer – Uses an external, locally compiled Unreal Engine folder for faster and leaner development.

This setup improves developer experience by enabling a VS Code DevContainer workflow and optimizing build processes for both Docker modes.

Key Features

New Docker Approaches

  • Monolithic (Self-contained)
    • Bundles Unreal Engine 4.26 and CARLA into a single Docker image.
    • Simplifies setup but requires significant build time (~100GB+ image).
  • Lightweight DevContainer
    • Uses an existing local Unreal Engine build to compile CARLA inside a leaner container.
    • Reduces Docker image size and dramatically speeds up development.

Scripts for Easy Setup

  • run_container.sh → Detects monolithic (--monolith flag) vs. lightweight mode.
  • build_image.sh → Handles image creation, including Epic Games credential management for UE4 builds.

Updated Dockerfiles

  • carla.dockerfileLightweight mode (requires externally mounted UE4).
  • carla-ue4.dockerfileMonolithic mode (builds UE4 and CARLA in one image).

DevContainer Support (VS Code)

  • Adds .devcontainer/devcontainer.json for easy development inside VS Code.
  • Enables NVIDIA GPU passthrough for CARLA simulation in containerized environments.

How to Use

Lightweight Mode (Faster)

export UE4_ROOT=/absolute/path/to/UnrealEngine_4.26  # Use an existing Unreal Engine build
./Scripts/run_container.sh  # Starts container
make PythonAPI && make CarlaUE4Editor  # Build inside the container

Monolithic Mode (Self-contained)

echo "EPIC_USER=username" >> .env  # Add Epic Games credentials
echo "EPIC_PASS=your_github_token" >> .env
./Scripts/run_container.sh --monolith  # Builds full image with UE4 + CARLA

Known Issues

  • Disk Space: The monolithic image exceeds 100GB. Ensure you have sufficient storage.
  • Backward Compatibility: Changes are untested with Python 2.7.
  • UE4 Setup Required: Lightweight mode requires a precompiled Unreal Engine on the host.

dorn-gerhard and others added 30 commits February 2, 2024 12:07
Updated the script to use curl instead of wget for downloading the FBX SDK, as the Autodesk server rejects wget requests with HTTP 403 errors. Added a Mozilla/5.0 user-agent to mimic browser behavior and ensure compatibility. This change resolves download issues and maintains the existing unpacking and build process.
If you must use Unreal's Clang, explicitly pass the library paths (/usr/lib/x86_64-linux-gnu) to the linker. This ensures the linker can find libpthread.so.0, libicuuc.so.70, and liblzma.so.5.
Copy link

update-docs bot commented Jan 31, 2025

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update our CHANGELOG.md based on your changes.

@wambitz wambitz changed the title Ubuntu 22.04 based image devcontainer [Feature] CARLA DevContainer & Docker Improvements – Ubuntu 22.04 Jan 31, 2025
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file could be removed and leave the reference on the documentation: Docs/build_docker_ubuntu22.md

@@ -144,10 +144,10 @@ if ${BUILD_CARLAUE4} ; then

OPTIONAL_MODULES_TEXT=""
if ${USE_CARSIM} ; then
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: This removes backward compatibility with Python 2.7 (deprecated). There is no need for newer releases and images.

If not specified as and argument:

$ python
bash: python: command not found

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to remove Python 2 as a dependency. @Blyron @MarcelPiNacy-CVC What do you think?

@@ -110,10 +110,10 @@ if ${DO_CARLA_RELEASE} ; then
pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null

if ${USE_CARSIM} ; then
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: This removes backward compatibility with Python 2.7 (deprecated). There is no need for newer releases and images.

If not specified as and argument:

$ python
bash: python: command not found

@@ -18,11 +18,11 @@ fi
# check if the XODR file exist
if [ -f "$1.xodr" ]; then
# parse openDRIVE crosswalks (generate crosswalks.obj)
python get_xodr_crosswalks.py -f "$1.xodr"
python3 get_xodr_crosswalks.py -f "$1.xodr"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: This removes backward compatibility with Python 2.7 (deprecated). There is no need for newer releases and images.

If not specified as and argument:

$ python
bash: python: command not found

@wambitz wambitz marked this pull request as ready for review January 31, 2025 02:07
@wambitz wambitz requested a review from a team as a code owner January 31, 2025 02:07
@wambitz
Copy link
Author

wambitz commented Jan 31, 2025

Testing --monolith

image

@wambitz
Copy link
Author

wambitz commented Jan 31, 2025

Testing devcontainer:

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: This file could be removed and just leave the reference in Docs/build_docker_ubuntu22.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we would leave this file here, but I’m considering the experience for Windows users. When they open the project in vscode, they’ll see a message suggesting that it can be opened in a container. But this doesn’t actually work on Windows. I’m not sure if there’s a good workaround for this. If we can’t find one, I’d suggest moving this to the documentation as a reference for now instead of keeping the file here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joel-mb I agree, this kind of file it's normally not committed. I can add it as a reference in the documentation. The scripts already take care of this, therefore this is just the translation in case a developer wants to use VS Code Devcontainers. I'll do the update, thanks for the feedback.

@qhaas
Copy link
Contributor

qhaas commented Apr 26, 2025

The ability to build UE / CARLA from source mounted from the host is an improvement for developers!

@joel-mb
Copy link
Contributor

joel-mb commented May 15, 2025

Hi @wambitz ! Thanks for this contribution and sorry for the late reply. I think this is a valuable addition to the community, as it facilitates working with CARLA from source on Linux. I’ll leave some minor comments, but overall the PR looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we would leave this file here, but I’m considering the experience for Windows users. When they open the project in vscode, they’ll see a message suggesting that it can be opened in a container. But this doesn’t actually work on Windows. I’m not sure if there’s a good workaround for this. If we can’t find one, I’d suggest moving this to the documentation as a reference for now instead of keeping the file here.

@@ -144,10 +144,10 @@ if ${BUILD_CARLAUE4} ; then

OPTIONAL_MODULES_TEXT=""
if ${USE_CARSIM} ; then
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
python3 ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to remove Python 2 as a dependency. @Blyron @MarcelPiNacy-CVC What do you think?

# ------------------------------------------------------------------------------
# Cleanup
# ------------------------------------------------------------------------------
RUN rm -rf /var/lib/apt/lists/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this cleanup isn't taking effect due to how Docker layers work. Deleting files in a later layer doesn't reduce the final image size. The cleanup should be included in the same RUN instruction as the apt update. Resolving this for now to avoid blocking the PR.

…ate documentation (#4)

Fixes an issue where containers would start in the right directory instead of the expected /workspaces/<REPO_NAME>. This would case trouble when launching from devcontainer.json
@wambitz
Copy link
Author

wambitz commented May 26, 2025

@joel-mb I made the appropriate changes, I went through the instructions and I made a few modifications to improve the reading flow, also I catch a small mounting "bug", the scripts were not mounting in the same directory as when using the devcontainer from VS Code. If fixed that so now it doesn't matter where you build from, either opening the container with the scripts or from VS Code devcontainer.

I tested these 3 options:

  • Launched container from scripts and open CARLA with make launch
  • Launched container from VS Code and open CARLA with 'make launch`
  • Launch from monolith container and open CARLA with make launch-only

@@ -50,3 +51,6 @@ _out*
_site
core
profiler.csv
.env
.venv
devcontainer.json
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remak: I added this so if someone decides to use devcontainer.json configuration it doesn't get committed by accident


You can use a **Visual Studio Code devcontainer** with the lightweight approach. This setup mounts your host’s directories (including UE4) into a Docker environment. Note that the monolithic image is less suited to devcontainers since it stores everything inside the image.

Create `.devcontainer/devcontainer.json` in your CARLA repository:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: His is the configuration I used to test the devcontainer from VS Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants