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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6ee572e
Update semantic labels (changed from version 0.9.13 -> 0.9.14)
dorn-gerhard Feb 2, 2024
3958e35
Add "Other" Label description in ref_sensors.md
dorn-gerhard Feb 2, 2024
24d135c
Revert "Add "Other" Label description in ref_sensors.md"
Blyron Feb 2, 2024
5515d3f
Revert "Update semantic labels (changed from version 0.9.13 -> 0.9.14)"
Blyron Feb 2, 2024
7636873
Update Master URLS
Blyron Mar 1, 2024
d2c87e5
Update tuto_A_add_vehicle.md removed euw
Blyron Mar 4, 2024
a2b433c
Update README.md
Blyron Mar 4, 2024
723f2c4
Update README.md
Blyron Mar 4, 2024
60bd026
updated master README (#7204)
MattRoweEAIF Mar 4, 2024
120ed2c
ci: ignore pytho venv and build dir
wambitz Jan 17, 2025
fc8c826
ci: docker integration for ubuntu22 devcontainer
wambitz Jan 17, 2025
804dcd9
fix: comment out corrupted link (empty file)
wambitz Jan 17, 2025
686401d
feat: support for GUI inside container
wambitz Jan 19, 2025
d7ba3d1
feat: GUI container support, UE4 install
wambitz Jan 22, 2025
934b03d
feat: force carla scripts to use python3
wambitz Jan 22, 2025
9ae6f18
feat: monolitic carla image
wambitz Jan 23, 2025
83ff570
fix : delete temporary file
wambitz Jan 23, 2025
e5413cb
feat: run carla in container with UE4 mounted from host
wambitz Jan 27, 2025
7be8e03
feat: add support for mounted and on image ue4
wambitz Jan 28, 2025
bc4e64f
feat: move dockerfiles to follow carla conventions
wambitz Jan 28, 2025
2a7ccb5
docs: rename ubuntu18 based dockerfile to CarlaLegacy to avoid confusion
wambitz Jan 28, 2025
4a57d62
fix: use curl instead of wget for FBX SDK download
wambitz Jan 28, 2025
39b6382
docs: remove docker reference at main README
wambitz Jan 28, 2025
273ca6d
fix: explicitly pass the library paths
wambitz Jan 28, 2025
8c13275
fix: remove progress=plain, it doesn't help with truncated output
wambitz Jan 29, 2025
c619b4a
fix: workspace conflict for different images
wambitz Jan 29, 2025
8faa3c4
chores: clean-up dockerfiles
wambitz Jan 29, 2025
99c063f
fix: build requires recommended packages
wambitz Jan 29, 2025
d4442a2
fix: rename workdir to match VS Code default mount dir name for devco…
wambitz Jan 30, 2025
5165441
feat: add shortcut for --monolith argument
wambitz Jan 30, 2025
9a17fcb
docs: create documentation for devcontainer usage
wambitz Jan 30, 2025
598757f
chore: cleanup devcontainer file
wambitz Jan 30, 2025
05591da
Merge branch 'ue4-dev' into feature/carla-0.9.15.2-jammy-devcontainer
wambitz Jan 30, 2025
9d9e5ed
fix: add unzip, missing after merge ue4-dev
wambitz Jan 30, 2025
5e13498
chore: remove unecessary file ignore
wambitz Jan 30, 2025
eb3c932
chore: include back shipping targets
wambitz Jan 30, 2025
5fe7dcf
Merge pull request #1 from wambitz/feature/carla-0.9.15.2-jammy-devco…
wambitz Jan 30, 2025
50bb023
Merge branch 'carla-simulator:ue4-dev' into ue4-dev
wambitz Jan 30, 2025
75a7448
fix: refence to default branch not custon branch
wambitz Jan 30, 2025
e59b276
fix: add unzip for devcontiner, missing dependency for make package
wambitz Jan 30, 2025
5873a20
Merge pull request #2 from wambitz/hotfix/reference-to-default-branch
wambitz Jan 31, 2025
a1036c0
Update CHANGELOG.md
wambitz Jan 31, 2025
4b919d8
Merge pull request #3 from wambitz/update-changelog
wambitz Jan 31, 2025
6aa9e7e
feat: improve readability, remove devcontainer.json and clean and upd…
wambitz May 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Plugins
!Unreal/CarlaUE4/Plugins
Unreal/CarlaUE4/Plugins/Streetmap
Unreal/CarlaUE4/Plugins/HoudiniEngine
build/


/ExportedMaps
Expand Down Expand Up @@ -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

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## Latest Changes
* Renamed Ubuntu 18-based Dockerfile to CarlaLegacy for clarity
* Created documentation for using devcontainers
* Ensured CARLA scripts consistently use python3
* Replaced wget with curl for FBX SDK downloads
* Enabled mounting of UE4 from the host when running CARLA inside a container
* Added support for GUI inside containers with Ubuntu 22 image
* Fixed waypoint.next and .previous causing loops when two opposite-direction lanes follow each other in the map.
* Fixed a bug that caused navigation information not to be loaded when switching maps
* Prevent from segfault on failing SignalReference identification when loading OpenDrive files
Expand Down
12 changes: 12 additions & 0 deletions Docs/build_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@ Any issues or doubts related with this topic can be posted in the CARLA forum.
CARLA forum</a>
</p>
</div>

---

## Devcontainer: Ubuntu 22.04 based image

_These instructions have been tested in **Ubuntu 24.04**._

The following documentation is intended to explain how to build a Docker image that uses **Ubuntu 22.04** to compile Carla.

- [CARLA Docker Dev Environment (Ubuntu 22.04)](./build_docker_ubuntu22.md)

---
246 changes: 246 additions & 0 deletions Docs/build_docker_ubuntu22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
# CARLA Docker Dev Environment (Ubuntu 22.04)

This repository provides **two** distinct Docker-based approaches for building and running **CARLA (version UE4)** on **Ubuntu Jammy (22.04)**:

1. **Monolithic**
- Bundles Unreal Engine (UE4) and CARLA into a single Docker image.
- Requires a lengthy build process and produces a large final image (often 100+ GB).
- Creates a fully self-contained environment with everything compiled inside Docker.

2. **Lightweight Devcontainer**
- Installs only the dependencies (plus NVIDIA support) required to compile and run CARLA.
- Requires mounting an existing **UE4** build from the host into the container (see [Build UE4 for Devcontainer Option](#build-ue4-prerequisite-for-lightweight--devcontainer)).
- Much faster to build but relies on a locally compiled Unreal Engine folder.

Your choice between **monolithic** and **lightweight** depends primarily on disk space, build times, and whether you prefer a fully self-contained environment (monolithic) or a setup that reuses a locally compiled Unreal Engine (lightweight).

---

## Overview

Two main scripts in the `Scripts/` directory manage building and launching the Docker containers:

1. **`run_container.sh`**
- Detects **monolithic** or **lightweight** mode via the `--monolith` (or `-m`) argument.
- If `--monolith` is present, uses `carla-ue4.dockerfile` (monolithic). Otherwise, defaults to `carla.dockerfile` (lightweight).

2. **`build_image.sh`**
- Generally called indirectly by `run_container.sh`.
- Checks whether `--monolith` was provided and chooses the corresponding Dockerfile.
- Handles Epic credentials (from a `.env` file) needed for cloning and building Unreal Engine in the monolithic mode.

---

## Dockerfiles in `Util/Docker/`

### `carla.dockerfile` (Lightweight / Devcontainer)

- Installs only CARLA dependencies, plus NVIDIA GPU support.
- **Excludes** Unreal Engine; instead, a precompiled UE4 folder (matching Carla’s requirements) must be mounted from the host via `UE4_ROOT`.
- Ideal for developers who already have a compatible UE4 build and want faster builds with smaller images.

### `carla-ue4.dockerfile` (Monolithic)

- Clones Unreal Engine from Epic’s private GitHub (requires valid Epic credentials). **If you don't have this set up, please follow [this guide](https://www.unrealengine.com/en-US/ue4-on-github) before going any further**.
- Compiles UE4 and then CARLA within a single Docker image, which may exceed 100 GB and take multiple hours to build.
- The image **retains** the `Dist/` directory, enabling you to run or extract the packaged CARLA binaries without additional scripts like `docker_tools.py` in comparison to `CarlaLegacy.Dockefile`. Although this makes the final image large, modern hardware generally has sufficient resources (e.g., larger SSDs, more RAM) to handle this scale. It also eliminates the need to repeatedly rebuild or rely on external tooling.

You can extract the CARLA package from a monolithic image using a simple Docker command sequence (replacing `0.9.15.2` with your CARLA version):

```bash
docker create --name temp_container carla-0.9.15.2-ue4-jammy-dev
docker cp temp_container:/workspaces/carla-0.9.15.2/Dist/CARLA_$(docker run --rm carla-0.9.15.2-ue4-jammy-dev ls /workspaces/carla-0.9.15.2/Dist | grep CARLA_).tar.gz .
docker rm temp_container
```

If disk usage is a concern and you do not need the final packaged artifacts, you can comment out `make build.utils` and `make package` in `carla-ue4.dockerfile`, or switch to the lightweight approach.

---

## Build UE4 (Prerequisite for Lightweight / Devcontainer)

> Note: Ensure your GitHub account is linked to Epic’s UnrealEngine repository before attempting to clone.

If you plan to use the **lightweight** approach, you need a **compiled** Unreal Engine folder on your host that matches CARLA’s requirements (usually UE4.26). You have the 2 following uptions

### Option 1: Build Natively

Follow CARLA official documentation: [Unreal Engine - Linux Build](https://carla.readthedocs.io/en/latest/build_linux/#:~:text=wheel%20auditwheel%3D%3D4.0.0-,Unreal%20Engine,-Starting%20with%20version)

### Option 2: Build UE4 in Build Container


The following steps outline a general workflow for building UE4 inside a Docker container. For detailed instructions, refer to `Engine/Documentation/Docker/run_with_docker.md` in the cloned repository:

```bash
# Example of cloning a custom CarlaUnrealEngine repository
git clone [email protected]:wambitz/CarlaUnrealEngine.git CarlaUE4

cd CarlaUE4
Scripts/run_container.sh

# Inside the container follow official UE4.26 build steps:
./Setup.sh
./GenerateProjectFiles.sh
make

# Exit container
exit
```

These commands generate the required Unreal Engine binaries and store them persistently on your host. You can later reuse them for the CARLA devcontainer. To verify a successful compilation, run the following command inside (or optionally outside) the container:

```bash
Engine/Binaries/Linux/UE4Editor
```
---

## Scripts Usage

### 1. Lightweight Mode

This mode relies on a **locally compiled** Unreal Engine folder. You mount that folder into the container for building CARLA.

```bash
# 1) Set UE4_ROOT to your existing UE4 folder on the host:
export UE4_ROOT=/absolute/path/to/UnrealEngine_4.26

# 2) Run the container WITHOUT the --monolith flag:
./Scripts/run_container.sh

# 3) Once inside the container, build CARLA as usual:
./Update.sh
make PythonAPI
make CarlaUE4Editor

# Optionally build for distribution:
make build.utils
make package
```

- **Result**:
- Uses **`carla.dockerfile`** (lightweight).
- Mounts your host’s `$UE4_ROOT` folder into `/opt/UE4.26` inside the container.
- Expects a fully compiled UE4 on the host. See [Build UE4 for Devcontainer Option](#build-ue4-prerequisite-for-lightweight--devcontainer) for more details.

### 2. Monolithic Mode

In this mode, Docker clones and builds Unreal Engine, then compiles CARLA within the same image.

```bash
# 1) Create a .env file with your Epic credentials at the repo root:
# EPIC_USER=YourGitHubUsername
# EPIC_PASS=YourGitHubToken

# 2) Run the container WITH the --monolith flag:
./Scripts/run_container.sh --monolith
```

- **Result**:
- Uses **`carla-ue4-monolith.dockerfile`**.
- Builds UE4 and CARLA in one Docker image (commonly exceeding 200 GB).
- Takes significant time (hours) on most hardware.

---



## Using a Devcontainer for CARLA Server/Client Development

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


```jsonc
{
"name": "CARLA UE4 Dev (jammy)",
"image": "carla-ue4-jammy-dev",

"initializeCommand": "./Scripts/build_image.sh",

// We do NOT need to set "remoteUser" if the Dockerfile's default user is already correct
// but you can if you want to be explicit. Also "updateRemoteUserUID" can be false, since
// our Dockerfile already set the user to our exact UID/GID.
"updateRemoteUserUID": false,

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "bash"
},
"extensions": [
"ms-vscode.cpptools"
]
}
},

"postStartCommand": "bash",

// NOTE1: DO NOT pass --user here (we want the Dockerfile default user, not an override)
// NOTE2: Make sure /usr/share/vulkan/icd.d/nvidia_icd.json exist in the host
// NOTE3: Ensure UE4_ROOT environment variable is defined in host
"runArgs": [
"--rm",
"--name", "carla-ue4-jammy-devcontainer",
"--hostname", "carla-devcontainer",
"--env", "DISPLAY=${localEnv:DISPLAY}",
"--volume", "/tmp/.X11-unix:/tmp/.X11-unix",
"--volume", "/usr/share/vulkan/icd.d/nvidia_icd.json:/usr/share/vulkan/icd.d/nvidia_icd.json",
"--volume", "${localEnv:UE4_ROOT}:/opt/UE4.26",
"--gpus", "all"
]
}
```

### Important Devcontainer Notes

1. **GPU Access**: Install and configure the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html).
2. **X11 Forwarding**: Ensure `/tmp/.X11-unix` is accessible and `DISPLAY` is set properly on your host.
3. **UE4_ROOT Environment Variable**: Must be defined on your host so the devcontainer can mount the UE4 directory.
4. **Vulkan Support**: `/usr/share/vulkan/icd.d/nvidia_icd.json` must be exist in your host so the devcontainer can mount the vulkan configuration.

---

## Tips & Caveats

- **NVIDIA GPU**
For hardware acceleration, install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html).

- **Disk Space**
The monolithic image can exceed **200 GB** (e.g., ~221 GB in some builds). Ensure you have enough space before choosing this route.

- **Build Times**
- Monolithic mode: ~2 hours on a high-end workstation (e.g., Intel Core i9-14900KF, 64 GB RAM, RTX 4090).
- Lightweight mode: Much faster since it reuses a local UE4 build.

- **Volumes**
For lightweight mode, `$UE4_ROOT` must point to a fully compiled UE4. If incorrect or missing, builds will fail.

- **Epic Credentials**
In monolithic mode, store `EPIC_USER` and `EPIC_PASS` in a `.env` file in the project root.

- **Running Binaries on the Host**
**Do not** run `make launch` or `make launch-only` on your host after building in the container, because internal container paths (e.g., `/opt/UE4.26`) do not match your host environment.
If you need host access to CARLA binaries, first build a shipping package (`make build.utils && make package`), then run them from the resulting files in `Dist/` on the host.

- **Mount Directory**
Avoid modifying `/workspaces` if you’re using VS Code devcontainers, as it might force a rebuild. The container’s internal paths often differ from the host, making direct host launches problematic.


- **`Dist` Folder Handling**
Monolithic mode leaves `Dist` in place to facilitate direct usage. If you need a smaller image, remove or adjust `make build.utils` and `make package`.

---

## Known Issues

1. **Truncated Output in `./Update.sh`**
Sometimes, `./Update.sh` in the CARLA repository may truncate logs. A workaround is redirecting the output to a file and tailing it.

2. **Audio Support**
ALSA or PulseAudio are not pre-configured, so audio features might not work by default.

3. **UE4Editor Rebuilds**
In some cases, once `UE4Editor` (built in UE4.26) is opened or used to build CARLA, it may refuse to open again without a rebuild. Errors about missing plugins can occur, a scenario also observed in local (non-Docker) setups. The workaround is to rebuild from the repository using the container or a devcontainer, or carefully adjust configuration files.

---
4 changes: 2 additions & 2 deletions Docs/build_docker_unreal.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ __2. Build the final CARLA image.__
The following command will use the image created in the previous step to build the final CARLA image based on the current master branch (latest release) of the CARLA repository:

```sh
docker build -t carla -f Carla.Dockerfile .
docker build -t carla -f CarlaLegacy.Dockerfile .
```

If you would like to build a specific branch or tag of the CARLA repository, run the following command:

```sh
docker build -t carla -f Carla.Dockerfile . --build-arg GIT_BRANCH=<branch_or_tag_name>
docker build -t carla -f CarlaLegacy.Dockerfile . --build-arg GIT_BRANCH=<branch_or_tag_name>
```

---
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ CARLA uses one dependency as part of the Chrono integration:

CARLA uses the Autodesk FBX SDK for converting FBX to OBJ in the import process of maps. This step is optional, and the SDK is located [here](https://www.autodesk.com/developer-network/platform-technologies/fbx-sdk-2020-0)

This software contains Autodesk® FBX® code developed by Autodesk, Inc. Copyright 2020 Autodesk, Inc. All rights, reserved. Such code is provided "as is" and Autodesk, Inc. disclaims any and all warranties, whether express or implied, including without limitation the implied warranties of merchantability, fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of such code."
This software contains Autodesk® FBX® code developed by Autodesk, Inc. Copyright 2020 Autodesk, Inc. All rights, reserved. Such code is provided "as is" and Autodesk, Inc. disclaims any and all warranties, whether express or implied, including without limitation the implied warranties of merchantability, fitness for a particular purpose or non-infringement of third party rights. In no event shall Autodesk, Inc. be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of such code."
72 changes: 72 additions & 0 deletions Scripts/build_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -e

###############################################################################
# Usage:
# ./build_image.sh [--monolith]
#
# If --monolith is supplied, it will:
# - Use: carla-ue4.dockerfile
# - Tag: carla-ue4-jammy-dev
# - Pass EPIC creds as needed
#
# Otherwise (default/lightweight):
# - Use: carla.dockerfile
# - Tag: carla-ue4-jammy-dev
###############################################################################

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
PROJECT_NAME="$(basename "$PROJECT_ROOT")"
DOCKERFILES_DIR="${PROJECT_ROOT}/Util/Docker"

MONOLITH=0
if [[ "$1" == "--monolith" || "$1" == "-m" ]]; then
MONOLITH=1
echo "[INFO] Monolithic build enabled."
fi

if [ $MONOLITH -eq 1 ]; then
DOCKERFILE="carla-ue4-monolith.dockerfile"
IMAGE_NAME="carla-ue4-jammy-monolith"
else
DOCKERFILE="carla-ue4.dockerfile"
IMAGE_NAME="carla-ue4-jammy-dev"
fi

# ------------------------------------------------------------------------------
# Load .env file for EPIC_USER, EPIC_PASS, etc.
# (Optional for the lightweight version, but mandatory for monolith.)
# ------------------------------------------------------------------------------
if [ -f "${PROJECT_ROOT}/.env" ]; then
# shellcheck disable=SC2046
export $(grep -v '^#' "${PROJECT_ROOT}/.env" | xargs)
else
echo "[WARN]: .env file not found in ${PROJECT_ROOT}."
echo "If you are building the monolithic version, you need EPIC credentials!"
fi

if [ $MONOLITH -eq 1 ]; then
# Ensure credentials are loaded for UE4
if [ -z "${EPIC_USER}" ] || [ -z "${EPIC_PASS}" ]; then
echo "[ERROR]: EPIC_USER or EPIC_PASS not set in the .env file. Aborting monolithic build."
exit 1
fi
fi

# ------------------------------------------------------------------------------
# Build the Docker image
# ------------------------------------------------------------------------------
echo "[INFO] Building Docker image '${IMAGE_NAME}' using Dockerfile '${DOCKERFILE}'"

# We always build in the project root so Docker sees the Dockerfile paths
docker build \
-f "${DOCKERFILES_DIR}/${DOCKERFILE}" \
-t "${IMAGE_NAME}" \
--build-arg EPIC_USER="${EPIC_USER:-}" \
--build-arg EPIC_PASS="${EPIC_PASS:-}" \
--build-arg USERNAME="$(whoami)" \
--build-arg USER_UID="$(id -u)" \
--build-arg USER_GID="$(id -g)" \
--build-arg PROJECT_NAME="${PROJECT_NAME}" \
"${PROJECT_ROOT}"
Loading