Docker Community Forums

Share and learn in the Docker community.

Multiple containers can share one single Base image ? Is it possible?


(Ameyrk) #1

Hi All,

I have one simple question.

Is it possible to share a single base image (OS) between multiple containers ?

For example 4 Apache web-servers containers sharing one single base image.

Best Regards,
Amey


(Sven Dowideit) #2

yes, in fact that’s a very useful and advisable way to do it - as the
shared layers reduce download time, and simplify maintenance

Sven

Docker Engineer
Ask me anything …
Brisbane, Australia (UTC+10)


(Ameyrk) #3

Hi Sven,

Is that possible ?

4 containers I want them in one server. 1st container is tomcat , 2nd container is web server, 3rd container is MySQL and 4th container is mongodb. Is it possible to share only one base image for these 4 containers ?

Regards,
Amey


(Jeff Anderson) #4

Yes, each of your four images would all have a Dockerfile that start with the same base image.

For example, I could have my tomcat Dockerfile look something like this:

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y install tomcat
...

My MySQL container could look something like this:

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y install mysql
...

(where ... fills out the rest of the image to get it to a working/desirable state)

Both of those images have the same base image (ubuntu:14.04). You can repeat this for as many images as you would like.

/Jeff


(Ameyrk) #5

Thanks Jeff for your prompt reply :smile:


(Test96) #6

Hi ,

i have to develop Single Docker image with multiple tomcat servers.Let me explain in brief

I have 4 spring mvc java modules each module gives respective project name *.war file
1.MA (Tomcat Port :9081)
2.GM (Tomcat Port :9090)
3.VG (Tomcat Port :9091)
4.DR (Tomcat Port :9092)

Now i took base image as Tomcat:8 (/usr/local/tomcat/webapps)
Now i have to develop above 4 modules with different tomcat server folders on top of base image

docker run -it -d -p 9081:8080 s33reqr343ef (imageID) (It is running on 9081) but my requirement is without specifying port number in above run command how to tomcat will run respective port and how to run all four diff tomcat server folders on same image

i have to push image with four diif tomcat servers to docker hub.when i pull and run that image should able to access all above modules with respective ports without specying them on run command