trzeci/emscripten
A complete container that allows to compile Emscripten and WebAssembly projects
1M+
In favour of the official image: https://hub.docker.com/repository/r/emscripten/emsdk Please investigate transition to those images. In case of missing features or bugs, please report them to https://github.com/emscripten-core/emsdk/
Based on: trzeci/emscripten-slim
A complete container that is required to compile C++ code with Emscripten. The goal was to provide a container that includes the most popular development packages and it's also easy to extend. Each tag was build from Dockerfile
packages | version |
---|---|
cmake | 3.14.3 |
package | version |
---|---|
ant | 1.10.5-2 |
build-essential | 12.6 |
ca-certificates | 20200601~deb10u1 |
curl | 7.64.0-4+deb10u1 |
git | 1 |
libidn11 | 1.33-2.2 |
libxml2 | 2.9.4+dfsg1-7+b3 |
make | 4.2.1-1.2 |
openjdk-11-jre-headless | 11.0.7+10-3~deb10u1 |
openssh-client | 1 |
python | 2.7.16-1 |
python-pip | 18.1-5 |
python3 | 3.7.3-1 |
python3-pip | 18.1-5 |
unzip | 6.0-23+deb10u1 |
wget | 1.20.1-1.1 |
zip | 3.0-11+b1 |
Used templates:
{VERSION}
: One of the official Emscripten tag released since 1.34.1. i.e. 1.38.25
{BRANCH}
: one of ["incoming", "master"]
tag | description |
---|---|
latest | The default version (aka latest ) points at the latest tag release by Emscripten. |
{VERSION}-upstream | Then newest and greatest version of Emscripten, based on Clang10. |
{VERSION}-fastcomp | Legacy version of Emscripten that's based on modified Clang 6. Soon to be deprecated. |
{VERSION}-ubuntu | Alias to version stored in trzeci/emscripten-ubuntu Based on custom fastcomp build |
{VERSION}-slim | LEGACY: Alias to version stored in trzeci/emscripten-slim Based on custom fastcomp build that is extra size optimized |
{VERSION} | LEGACY: Based on trzeci/emscripten-slim - custom fastcomp build |
sdk-tag-{VERSION}-64bit | LEGACY: Tag release |
sdk-{BRANCH}-64bit | LEGACY: Branch release |
Tags marked as legacy are no longer build. The recommended way is to use the upstream version.
Every Emscripten command is available inside container. For the instance: emcc
, em++
, emmake
, emar
, node
, asm2wasm
etc.
To compile a single file:
docker run --rm -v `pwd`:`pwd` trzeci/emscripten emcc helloworld.cpp -o helloworld.js
More elaborated Hello World:
# create helloworld.cpp
cat << EOF > helloworld.cpp
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
EOF
# compile with docker image
docker run \
--rm \
-v $(pwd):$(pwd) \
-u $(id -u):$(id -g) \
trzeci/emscripten \
emcc helloworld.cpp -o helloworld.js
# execute on host machine
node helloworld.js
Teardown of compilation command:
part | description |
---|---|
docker run | A standard command to run a command in a container |
--rm | remove a container after execution (optimization) |
-v $(pwd):$(pwd) | Mounting current folder from the host system into mirrored path on the container TIP: This helps to investigate possible problem as we preserve exactly the same paths like in host. In such case modern editors (like Sublime, Atom, VS Code) let us to CTRL+Click on a problematic file |
-u $(id -u):$(id -g) | (1.37.23+) Run a container as a non-root user with the same UID and GID as local user. Hence all files produced by this are accessible to non-root users |
trzeci/emscripten | Get the latest tag of this container |
emcc helloworld.cpp -o helloworld.js | Execute emcc command with following arguments inside container, effectively compile our source code |
If you would like to extend this image you have two choices:
An example how to derive from base image and keep linux base container you can find here : trzeci/emscripten/Dockerfile.
All what you need is:
FROM trzeci/emscripten:1.39.17-upstream
# A good practice is to don't use `latest` - even if some effort is made to make sure that `latest` version is stable
RUN ...
This way you inherit all settings of environment that are coming with this image and entrypoiont.
An example how to derive from base image and switch linux base container you can find here - trzeci/emscripten-ubuntu/Dockerfile.
An example that uses Docker multi-stage build:
FROM trzeci/emscripten:1.39.17-upstream as emscripten_base
# Target base image
FROM fedora
# Copy pre-compiled content of Emscripten SDK to target iamge
COPY --from=emscripten_base /emsdk_portable /emsdk_portable
# install required tools to run Emscripten SDK
RUN dnf install -y python python-pip ca-certificates
# Use entrypoint that comes with Emscripten. This is a way to to activate Emscripten Tools.
ENTRYPOINT ["/emsdk_portable/entrypoint"]
That's all! All you need is to copy content from /emsdk_portable
to the same folder in your image.
Then it's important to use /emsdk_portable/entrypoint
as it contains some nice fixes for non-root file access rights.
Alternatively you can also call:
. /emsdk_portable/emsdk_set_env.sh
in your entrypoint - it will work just fine!*
* In vast majority of cases, if it doesn't due $PATH
override please get familiar with Entrypoint-less
case
Entrypoint
Important step is to activate Emscripten SDK - so that tools are available for usage. Most traditional way is to use entrypoint and this image provides one:
ENTRYPOINT ["/emsdk_portable/entrypoint"]
Entypoint-less
In case when you can't override entrypoint or you have to have Emscripten Ready as a docker stage step, or activation script messes up with your system $PATH
- you might use an alternative method - let's say static activation.
For that instead of adding ENTRYPOINT
you need to add:
# Setup Emscripten Environment variables
ENV EMSDK /emsdk_portable
ENV EMSCRIPTEN=${EMSDK}/emscripten/sdk
ENV EM_DATA ${EMSDK}/.data
ENV EM_CONFIG ${EMSDK}/.emscripten
ENV EM_CACHE ${EM_DATA}/cache
ENV EM_PORTS ${EM_DATA}/ports
# Expose tools to system PATH
ENV PATH="${EMSDK}:${EMSDK}/emscripten/sdk:${EMSDK}/llvm/clang/bin:${EMSDK}/node/current/bin:${EMSDK}/binaryen/bin:${PATH}"
Basically you can use whatever base system of choice and copy content of /emsdk_portable
from either emscripten
or emscripten-slim
and start use it.
python -m builder compile 1.39.17
which will build all variants of SDK (emscripten-slim, emscripten, emscripten-ubuntu) and perform tests on those../docker
path, let's say ./docker/trzeci/emscripten-upstream
.docker build -t my_little_emscripten_image --build-arg EMSCRIPTEN_VERSION=1.39.17 .
As EMSDK and Emscripten and even this Docker Image are under an extensive development some scripts might change in meantime.
To be extra accurate, you can check which version of EMSDK was used in a particular image. For older images you can check a file otherwise for images 1.38.9+ execute a command docker run --rm -it trzeci/emscripten:sdk-tag-1.38.9-64bit bash -c "git -C /emsdk_portable rev-parse HEAD"
Found changeset should be used as docker build
argument - EMSDK_CHANGESET
Since 1.38.33
Dockerfiles are added to the image under /emsdk_portable/dockerfiles
folder to get a copy of those please execute:
# following command will tar dockerfiles form image and export files under host's filesystem in 'dockerfiles' folder.
docker run --rm trzeci/emscripten-slim:sdk-tag-1.38.33-64bit tar -c -C /emsdk_portable dockerfiles | tar xv
Then it's possible to have a full inspection to exact the same Docker file that were used for image building.
Older images:
A: Execute command line:
# example for 1.38.25
tag=sdk-tag-1.38.25-64bit
docker pull trzeci/emscripten:${tag} > /dev/null
docker inspect --format '{{ index .Config.Labels "org.label-schema.vcs-ref"}}' trzeci/emscripten:${tag}
B: Use microbadger portal:
org.label-schema.vcs-ref
property that should hold changeset of emscripten-docker
repository that was used during build process.(Please note that following history refers only to the history of this Docker Image and how it was build / what includes. For release notes of emscripten, please follow https://emscripten.org)
1.39.17: It's over 1M pulls of this image! :tada: Thank you so much! Starting from this tag there is a couple of changes in the tag convention and compiled flavors.
latest
tag will be always pointing to that flavour1.39.5: #67 - Added precompiled LTO object
1.38.34: #45, #46 - (Cumulative change) Adopt image to new Emscripten SDK
/emsdk_portable
is fully moveable folder that can be used as a COPY --from
source of multi stage build/emsdk_portable/dockerfiles
contains Dockerfile sources used to compile a particular image - so that it should be fairly easy to replicate and inspect content of imagesemsdk
should be fully functional tool now, so that can be used for upgrading bundled emscripten SDK or to install extra toolsdebiang:stretch-slim
$PATH
nodejs
is no longer symlinked (node
should be used instead)1.38.33: Version ignored due problem with dependencies
1.38.30: #40 Fixed image compilation problem caused by JRE backport package
1.38.22: #35 upgrade to cmake
3.12.2
1.38.17: Version ignored due problems with [Emscripten]
1.38.9: /emsdk_portable
will be preserved as a git repos (with valid version of changeset)
1.38.7: Version removed due problems with emsdk
1.37.29: upgrade to cmake
3.7.2
1.37.23: Added curl
, zip
, unzip
, upgrade to openjdk-jre-8
1.37.21: Fixed missing ctest
command
1.37.21: image includes ssh
and cache of libc libcxx is fixed.
1.37.19: image doesn't use entrypoint from the base image.
1.37.18: it contains perl
and git
package
1.37.16: images are compiled from singe Dockerfile.
1.37.10: images are bundled with java
1.36.7: images are bundled with make
and nodejs
1.36.7: images are bundled with cmake
3.6.3, images are build from generated Dockerfiles
1.35.0: images base on Debian
1.34.X: images base on Ubuntu:15.10
Generated by jenkins: 2020-06-13T00:17:53.319432
docker pull trzeci/emscripten