A command line utility for executing code in many different languages using the Docker Exec images, written in Go.
Download the appropriate binary for your OS and architecture, then unzip or untar and move the dexec
executable to where it can be found on your PATH.
OS | 64-bit | 32-bit |
---|---|---|
Linux | 64-bit | 32-bit |
Mac | 64-bit | 32-bit |
Windows | 64-bit | 32-bit |
Binaries for other distributions are available on Bintray.
If you have Go installed and configured correctly, you can install dexec
with the go get
command.
$ go get github.com/docker-exec/dexec
These examples use a .cpp source file, but any of the supported languages can be used instead. Arguments can be passed in any order, using any style of the acceptable switch styles described.
The application provides help and version information as follows:
$ dexec --version
$ dexec --help
Multiple source files can be passed to the compiler or interpreter as follows. The first source file's extension is used to pick the appropriate Docker Exec image, e.g. .cpp retrieves dexec/cpp from the Docker registry.
$ dexec foo.cpp
$ dexec foo.cpp bar.cpp
The sources are mounted individually using the default Docker mount permissions (rw) and can be specified by appending :ro or :rw to the source file.
For compiled languages, arguments can be passed to the compiler.
$ dexec foo.cpp --build-arg=-std=c++11
$ dexec foo.cpp --build-arg -std=c++11
$ dexec foo.cpp -b -std=c++11
Arguments can be passed to the executing code. Enclose arguments with single quotes to preserve whitespace.
$ dexec foo.cpp --arg=hello --arg=world --arg='hello world'
$ dexec foo.cpp --arg hello --arg world --arg 'hello world'
$ dexec foo.cpp -a hello -a world -a 'hello world'
By default, dexec assumes the sources are in the directory from which it is being invoked from. It is possible to override the working directory by passing the -C
flag.
$ dexec -C /path/to/sources foo.cpp bar.cpp
Individual files can be mounted without being passed to the compiler, for example header files in C & C++, or input files for program execution. These can be included in the following way.
$ dexec foo.cpp --include=bar.hpp
$ dexec foo.cpp --include bar.hpp
$ dexec foo.cpp -i bar.hpp
In addition, a program may require read and/or write access to several files on the host system. The most efficient way to achieve this is to include a directory.
$ dexec foo.cpp --include=.
$ dexec foo.cpp --include .
$ dexec foo.cpp -i .
Files and directories are relative to either the current working directory, or the directory specified with the -C
flag.
As with sources, included files and directories are mounted using the default Docker mount permissions (rw) and can be specified by appending :ro or :rw to the source file.
Primarily for debugging purposes, the --update command triggers a docker pull
of the target image before executing the code.
$ dexec foo.cpp -u
$ dexec foo.cpp --update
dexec
can be used to make source code executable by adding a shebang that invokes it at the top of a source file.
The shebang is stripped out at execution time but the original source containing the shebang preserved.
#!/usr/bin/env dexec
#include <iostream>
int main() {
std::cout << "hello world" << std::endl;
}
then
$ chmod +x foo.cpp
$ ./foo.cpp