Reputation: 283355
I want to run my unit tests against the latest versions of PHP and Node, which means I need both installed into one image for it to work with Bitbucket Pipelines.
What I've been doing until now is to pick one or the other as my base, and then manually install the other. e.g., I've started with php:5.6-fpm
as my base, and then installed Node:
# Dockerfile
FROM php:5.6-fpm
RUN docker-php-ext-install bcmath
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y git mercurial unzip nodejs
RUN npm set progress=false
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN php -r "unlink('composer-setup.php');"
Is there any way to utilize both PHP and Node for my image, and then install some stuff on top of that (e.g. Composer and Yarn)?
Upvotes: 1
Views: 901
Reputation: 256
You could create a image and commit
it either only locally on your machine by:
docker commit <container-id> image-name:tagname
from: https://docs.docker.com/engine/reference/commandline/commit/
then later use this image in new Dockerfile using FROM image-name:tagname
Everything that you will add to new Dockerfile will be stacked on top of that image you created with PHP and Node.js
Sometimes you could create several layers of images that will progress with different processes and functions. Very good reference is: https://hub.docker.com/u/million12/
So you can create a base image with PHP and then another using PHP image that has Node.js installed on it and then another with composer.
If you wish to export your images from your local machine you should register on docker hub and export to it or alternative service like quay.io
Hope that answered your question.
Upvotes: 1