Below is an example Dockerfile that starts from an OpenJDK 8 base image and installs Apache Ant along with the Emscripten SDK. You can adjust package lists or versions as needed.
# Use OpenJDK 8 as the base image (includes JDK 8)
FROM openjdk:8
# Install dependencies:
# - ant: for Java builds
# - git: to clone the emsdk repository
# - python2.7: required by emscripten (and create a "python" symlink)
# - wget, build-essential, cmake: additional tools that help emscripten and build processes
RUN apt-get update && apt-get install -y \
ant \
git \
python2.7 \
wget \
build-essential \
cmake \
&& rm -rf /var/lib/apt/lists/*
# Make sure that "python" points to Python 2.7 (emscripten expects a "python" executable)
RUN ln -s /usr/bin/python2.7 /usr/bin/python
# Install Emscripten SDK (emsdk)
# We clone the repository into /emsdk, install and activate the latest version
RUN git clone https://github.com/emscripten-core/emsdk.git /emsdk
WORKDIR /emsdk
RUN ./emsdk install latest && \
./emsdk activate latest
# Ensure the sdk environment variables are always set.
# This appends the source command into the global bash startup.
RUN echo "source /emsdk/emsdk_env.sh" >> /etc/bash.bashrc
# Optionally, export EMSDK and modify PATH so that emscripten tools are available in non-interactive sessions.
ENV EMSDK=/emsdk
ENV PATH="/emsdk:$PATH"
# Reset working directory to a default location for building your project
WORKDIR /build
# Default command (launches a bash shell)
CMD ["/bin/bash"]
Explanation
-
Base Image
We use openjdk:8 so that JDK 8 is preinstalled.
-
Dependency Installation
The apt-get install step includes:
- ant: Required to build Java projects.
- git: To clone the emsdk repository.
- python2.7: Emscripten currently requires Python 2.7. (If you’d like to use Python 3, consult the latest Emscripten docs to see if it’s supported.)
- wget, build-essential, cmake: Common tools that are often needed for native builds and by the SDK.
-
Python Symlink
Some scripts in the emsdk expect the command python to be available. Since the installed binary is python2.7, a symlink is created.
-
Emscripten Installation
The emsdk repository is cloned into the /emsdk directory. Then, using the provided scripts, we install and activate the latest SDK release.
(You can lock to a specific version if necessary.)
-
Environment Setup
We add source /emsdk/emsdk_env.sh to the global bash configuration so that every new shell session will have the proper environment variables set for Emscripten. We also export variables via the Dockerfile’s ENV commands.
-
Working Directory & CMD
The working directory is set to /build where you might mount your source code for building, and the container will launch into a Bash shell by default.
You can build this image with:
docker build -t mybuildimage .
Then run an interactive container:
docker run -it mybuildimage
This image is now ready for building Java (with Ant) and WebAssembly (via Emscripten) projects.