Seamlessly execute commands (composer, bower, compass) in isolation using docker and make.
# Install bower dependencies, without installing npm or bower locally
$ make bower install
# compile compass stylesheets, without installing ruby or compass locally
$ make compass build
# install composer dependencies faqster using HHVM, without installing HHVM locally
$ make composer install
make-docker-command doesn't change the syntax of your favorite commands: just prepend make
, and the command runs in a docker container. It uses docker images hosted on Docker Hub, and generates files with the right user credentials.
make-docker-command currently supports the following dockerized commands:
Tip: For command invocations with an option (like --prefer-source
), use make --
instead of make
:
$ make -- composer install --prefer-source
make-docker-command requires Docker 1.2, and works both on Linux and OSX.
For more details about the intention and the implementation, see the make-docker-command introduction post on the marmelab blog.
Copy the content of the Makefile
from this repository to the Makefile
of the projects you're working on.
Some commands may require SSH keys to connect to a secured repository (e.g. GitHub). make-docker-command will use the identity and hosts file declared in the DOCKER_SSH_IDENTITY
and DOCKER_SSH_KNOWN_HOSTS
environment variables (default to ~/.ssh/id_rsa
and ~/.ssh/known_hosts
).
If you don't want to enter a passphrase each time use these keys, create a new SSH key pair without passphrase and authorize it on GitHub:
$ cd ~/.ssh
$ mkdir docker_identity && cd docker_identity
$ ssh-keygen -t rsa -f id_rsa -N ''
$ ssh-keyscan -t rsa github.com > known_hosts
Then modify the environment variable to let make-docker-command
use the new key:
$ export DOCKER_SSH_IDENTITY="~/.ssh/docker_identity/id_rsa"
$ export DOCKER_SSH_KNOWN_HOSTS="~/.ssh/docker_identity/known_hosts"
Commands executed in a docker container run in about the same time on Linux. On OS X, commands with lots of disk I/Os are much slower when run inside a container. This is currently addressed by the Docker core team.
Install composer dependencies using the marmelab/composer-hhvm docker image, running composer on HHVM (faster than PHP).
$ make composer install
The composer cache persists between runs. The vendor
directory is created using the current user name and group. Private repositories are fetched using the SSH identity file.
Run PHP unit tests using the marmelab/phpunit-hhvm docker image, running phpunit on HHVM (faster than PHP).
$ make phpunit
Uses the marmelab/bower docker image, running bower on npm.
$ make bower install
The bower cache persists between runs. The bower_components
directory is created using the current user name and group. Private repositories are fetched using the SSH identity file.
Uses the marmelab/compass docker image, running bower on ruby.
$ make compass build
The user executing make command
must be a member of the docker
group to avoid using sudo:
$ sudo groupadd docker
$ sudo gpasswd -a my_user docker
$ sudo service docker restart
This warning shouldn't prevent the command from running, but the message means that your system needs an additional LXC configuration. See the official Docker documentation for the solution.
On hosts using AppArmor, docker containers can't execute commands as non-root, even if the executable bit is set for all. Try the following commands on the host:
$ apt-get install apparmor-utils
$ aa-complain /usr/bin/lxc-start
$ aa-complain /usr/bin/docker
Docker on OS X is still rough in the edges, and you'll need a custom version of boot2docker, allowing volume mounting, to get this working.
make-docker-command will only work when called from under the /Users/
directory (because that's the only directory shered between the host and the VM).
make-docker-command is available under the MIT license, courtesy of marmelab.
Comments and pull requests are welcome.