WARNING: This is a proof of concept! It’s not meant to be used in production.
This proof of concept
docker run wrapper attempts to make docker containers behave like unix processes.
It makes it easy to run docker containers under a process monitoring tool. It accepts the same options as
The final goal of this project is to merge most of this functionality into docker itself.
dockrun may be used for development. Pull requests, bug reports and questions are welcome.
This proof of concept is meant to show what improvements could be useful to docker. It’s also meant to be an attempt at making docker containers easier to monitor with process monitoring tools (systemd, supervisor & god).
It tries to bring the following features to docker run:
- return the exit code of the process when the container exists
- print logging output (stderr and stdout) during the execution of the container
- automatically remove the container when all operations are done if -rm is provided
- handle signals for process termination (SIGTERM/SIGINT)
- automatically commit the container and give it a repository name (optionally, a tag) if -commit reponame or -commit reponame:tag is provided
How it works
dockrun does the following in order to UNIX-ize docker containers:
- It runs
-cidfileso that it can retrieve the container ID.
- It attaches the stdin, stdout and stderr providede by
docker runto make the container behave like a real process.
- It runs
docker waitto wait for the container to exit & to get the exit code of the process running inside it.
- It sets up a signal handler to make the container behave like a UNIX process.
This handler makes sure that
docker stopgets executed in order to shut down the container and the process running within it.
- It commits the container if
-commit reponame:tagis provided if the container has exited with exit code 0.
- It runs
docker rmto remove the container before it exits when
-rmis provided. This lets us make dockrun stateless across runs.
- It exits with the same exit code as the process which was running in the container.
You need to have Go 1.1 installed to build this. You also need to have docker installed for this tool to work.
git clone https://github.com/unclejack/dockrun.git cd dockrun go build
dockrun was tested with docker 0.5.x.
You’ll find a few examples below.
Print “test” and automatically delete the container:
dockrun -rm ubuntu echo "test"
Start and expose a service running on port 5000 in the container via port 42850 on the host:
dockrun -p 42850:5000 myrepo/coolservice
Run a process which exits with exit code 3 and leaves the container behind:
$ dockrun ubuntu bash -c "exit 3" $ echo $? 3
Start a container, pipe the string “test” into it, print it to stdout, echo the string “bla”, exit with exit code 0, commit the container as image test:bla and remove the container:
echo "test" | dockrun -commit test:bla -i -rm ubuntu bash -c "cat && echo bla && exit 0"
- docker run options from the
-afamily aren’t supported by dockrun.
-rmmakes dockrun automatically remove the resulting container.
-commitmakes dockrun commit the container to the given reponame or reponame:tag.
dockrunmakes use of the
docker runoption to keep track of the container ID.