1. Create a folder
$ mkdir mytomcat
2. Switch to the folder
$ cd mytomcat
3. Generate a Dockerfile and edit the content
$ gedit Dockerfile
FROM ubuntu:16.04
ADD jdk-8u162-linux-x64.tar.gz /java/
ADD apache- tomcat-7.0.85.tar.gz /tomcat/
ENV JAVA_HOME=/java/jdk1.8.0_162
ENV PATH=$PATH:$JAVA_HOME/bin
EXPOSE 8080
CMD ["/tomcat/apache-tomcat-7.0.85/bin/ catalina.sh", "run"]
Why are the environment variables and startup sh files configured in the underlying image invalid at the top level? Use ENV to configure variables.
Commands tried during debugging:
#ADD dockerd /etc/rc.d/init.d/
#RUN chmod 777 /etc/rc.d/init.d/dockerd
#CMD /etc/rc.d/init.d/dockerd
#CMD /bin/bash
#CMD /tomcat/apache-tomcat-7.0.85/bin/startup.sh
#RUN ps -ef
4. Create an image
$ docker build -t mytomcat:v1 .
5. Create a container. Why sometimes containers don't start automatically? Because there is no "bash" command added.
$ docker run -it --name mytomcat -d mytomcat:v1
6. Check whether the container is started
$ docker ps -a
7. Query the ip corresponding to the container
$ docker inspect mytomcat
8. Open tomcat on the browser to verify whether it is successful
http:/ /172.17.0.2:8080/
9. Enter the container to verify whether the jdk service is started
$ docker exec -it mytomcat bash
root@3729b97e8226:/# ps -ef
root@3729b97e8226:/# exit
10. Commands attempted during debugging:
$ gedit dockerd
#!/bin/bash
/tomcat/apache-tomcat-7.0.85/bin/startup.sh
/bin/bash
exit 0
$ docker run -it --name mytomcat -d -p 81:8080 mytomcat:v1 /etc/rc.d/init.d/dockerd
cat /tomcat/apache-tomcat-7.0.85/conf/server.xml
docker container start mytomcat #Start project