dockerfile production details 1

Keywords: Docker Tomcat PHP RPM

1. Docker virtual image production practice I

1) Docker commit enables the container to be submitted as a new image. The submitted image automatically enters the image list of the current system (the contents of the container image are complete);

docker commit 7ec01484db55  centos7:v1

docker images

2) Docker export can implement container submission as a new image. The submitted image cannot automatically enter the image list of the current system, and can be submitted as a new tar file. (the image content will lose some data: currently running, in memory, environment variables, executing commands)

docker export 7ec01484db55 > centos7.tar

Command to import image;

cat centos7.tar |docker import - centos7:v3

3) Docker save tool can directly export the image as a. tar file. The command is as follows: (the image content is relatively complete)

docker save centos7:v1 -o centos7:v3.tar

You can import the save d image through docker load;

docker load -i centos7_v3.tar

 

2. Docker virtual image production practice II

# Set the basic image. Subsequent commands are based on this image

FROM docker.io/centos6:latest

# Author information

MAINTAINER  JFEDU.NET

# The RUN command will execute any command in the image specified above

RUN rpm --rebuilddb;yum install rpm-build -y

RUN rpm --rebuilddb;yum install httpd httpd-devel php php-devel php-mysql mysql-server mysql my

sql-devel -y

RUN echo -e "<?php\nphpinfo();\n?>">/var/www/html/index.php

RUN echo 1|passwd --stdin root

RUN cp /etc/skel/.bash* /root/

RUN mkdir -p /tmp/20501111

WORKDIR /root/

RUN su -

#Expose HTTP port 81

EXPOSE 80 3306 22

# Set the default command when running the image: output the ip and start sshd in the mode of daemon

CMD service httpd start;service mysqld start;service sshd start;/bin/bash

 

3. Docker virtual image production practice III


FROM docker.io/lemonbar/centos6-ssh

MAINTAINER  JFEDU.NET

WORKDIR /root

RUN cp /etc/skel/.bash* /root/

RUN mkdir -p /usr/local/tomcat/ /usr/java/

ADD tomcat/ /usr/local/tomcat/

ADD edu.war /usr/local/tomcat/webapps/ROOT/

ADD jdk1.8.0_131.tar.gz /usr/java/

RUN rpm --rebuilddb;yum install tar gzip* bzip* wget -y

RUN echo -e 'export JAVA_HOME=/usr/java/jdk1.8.0_131\nexport CLASSPATH=$CLASSPATH:$JAVA_HOME/li

b:$JAVA_HOME/jre/lib\nPATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin' >>/etc/profile

RUN source /etc/profile;cd /usr/local/tomcat/webapps/ROOT/;jar -xf edu.war

RUN echo '123456' | passwd --stdin root

EXPOSE  22 8080

# Set the default command when running the image: output the ip and start sshd in the mode of daemon

#CMD /usr/local/tomcat/bin/startup.sh;/usr/sbin/sshd -D

CMD set -m;source /etc/profile;/usr/local/tomcat/bin/startup.sh;/usr/sbin/sshd -D

Posted by nafetski on Sun, 05 Apr 2020 06:03:50 -0700