Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend an existing docker image?

I'm using the official elasticsearch Docker image instead of setting up my own elastic search instance. And that works great, up to the point when I wanted to extend it. I wanted to install marvel into that ElasticSearch instance to get more information.

Now dockerfile/elasticsearch automatically runs ElasticSearch and setting the command to /bin/bash doesn't work, neither does attaching to the container or trying to access it over SSH, nor installing ssh-daemon with apt-get install -y openssh-server.

In this particular case, I could just go into the container's file system and execute opt/elasticsearch/bint/plugin -i elasticsearch/marvel/latest and everything worked.

But how could I install an additional service which needs to be installed with apt-get when I can't have a terminal inside the running container?

like image 375
peter Avatar asked Apr 07 '14 07:04

peter


People also ask

What is Docker image extension?

A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments.


2 Answers

Simply extend it using a Dockerfile that start with

FROM dockerfile/elasticsearch 

and install marvel or ssh-server or whatever you need. Then, end with the correct command to start your services. You can use supervisor to start multple services, see Run a service automatically in a docker container for more info on that.

like image 97
qkrijger Avatar answered Oct 05 '22 14:10

qkrijger


If you don't mind using docker-compose, what I usually do is to add a first section for the base image you plan to reuse, and then use that image as the base in the rest of the services' Dockerfiles, something along the lines of:

--- version: '2' services:     base:         build: ./images/base      collector:          build: ./images/collector 

Then, in images/collector/Dockerfile, and since my project is called webtrack, I'd type

FROM webtrack_base ... 

And now it's done!

like image 45
mrArias Avatar answered Oct 05 '22 15:10

mrArias