As we have already discussed Docker is a great way to isolate your environment and stop items from crashing into each other. Following on from my last post about running tools from inside a container, we looked at running stuff into your container. Now I am going to have some real life examples. I already expect that you know how to mount your files/directories into the container (-v) and how to assign your workdir (-w), so if you don’t have a look at the last post.

Get Docker Image ID

To do this you are going to need to know your docker image ID’s. Here are some of mine.

➜  ~ docker images
REPOSITORY          TAG           IMAGE ID            CREATED          SIZE
bbcnews/wraith      latest        c675f285cbbc        2 days ago       1.192 GB
node                alpine        a1c188c2c5e1        4 days ago       55.29 MB
frapsoft/yarn       latest        ea15dfeff4f4        2 weeks ago      55.05 MB
composer/composer   alpine        6d48ee9405f5        9 weeks ago      317.6 MB

Running Composer install from inside a container

Composer is the PHP package manager and is used for a whole host of different tools, including PHPUnit, Behat, PHPCodesniffer and many more. However, how can you run it as a container?

docker pull composer/composer:alpine
docker run -v $(pwd):/app -w /app -it 6d48ee9405f5 require guzzlehttp/guzzle
composer ...

Running NPM/Yarn install from inside a container

NPM is the fantastically useful (and popular) node package manager and Yarn is a rebuild of that by Facebook that is slightly quicker. Using it inside a container?

NPM

docker pull  node:alpine
docker run -v $( pwd ):/app -w /app -it 164dad592f49 npm install forever
npm ...

Yarn

docker pull frapsoft/yarn
docker run -v $(pwd):/app -w /app -it 164dad592f49 add forever
yarn ...

Using Wraith (a rubygem) from inside a container

If you haven’t already heard of Wraith, you should probably look it up. It enables one of the most growing areas of test automation, visual regression. Where you do image comparison of screenshots to view changes, regressions or differences. But running it from a container?

docker pull bbcnews/wraith
docker run -v $(pwd):/app -w /app -it c675f285cbbc setup
...[SET UP YOUR WRAITH CONFIGS]
docker run -v $(pwd):/app -w /app -it c675f285cbbc capture configs/config.yaml