The difference between the two ways to create docker mirrored startup containers is described in the of summary

  • 2020-05-17 07:18:50
  • OfStack

Docker is built on the core of Linux. In the current mainstream Linux system, Docker is already supported natively and the experience is the best. Of course, Docker is also supported in Windows platform and MacOS system, but it is necessary to use virtualization tools such as Boot2Docker to provide Linux support.

The following highlights the differences between the two startup containers for creating docker images. Those interested can follow this site from 1 to learn!

1. When starting with the image generated by docker commit, you can load a script to start your own application, for example:


docker run -d -P tomcat7.0b:jdk1.6 /run.sh

The last/run.sh is to launch the tomcat application, which means to launch the tomcat application when starting the container. Otherwise you just start the container and don't start your own application.

run.sh reads as follows:


#!/bin/bash
/usr/sbin/sshd -D &
exec ${CATALINA_HOME}/bin/catalina.sh run

Also, notice that this container is currently instantiated based on the image generated from the Docfile file. If you do this and then use docker commit to generate a new image based on this container, then the container generated based on the new image will still have to load a step to start its own application.

2. No need to add this script when starting the container with the image generated by Docfile


FROM sshd3:ubuntu
MAINTAINER waitfish from dockerpool.com(978145009@qq.com)
ENV DEBIAN_FRONTEND noninteractive
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get install -yq --no-install-recommends wget pwgen ca-certificates && apt-get clean && rm -rf /var/lib/apt/lists/*
ENV CATALINA_HOME /tomcat 
ENV JAVA_HOME /jdk
ADD apache-tomcat-7.0.69 /tomcat
ADD jdk1.6.0_45 /jdk
#ADD create_tomcat_admin_user.sh /create_tomcat_admin_user.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
RUN chmod +x /tomcat/bin/*.sh
EXPOSE 8080
CMD ["/run.sh"]

Because the last sentence, CMD, means when you start the container, you call the script.


Related articles: