The article directories

  • First, install Tomcat
  • Second, test Tomcat operation
  • Verify whether to start
  • Create Dockerfile
  • Prepare server.xml
  • 6. Upload server. XML Dockerfile to Linux server
  • 7. Execute docker build compilation
  • View the generated image file
  • 9. Start Tomcat
  • Write at the end, thanks for the likes

First, install Tomcat

docker search Tomcat
docker pull Tomcat:8.0
Copy the code

I specify to pull Tomcat 8.0 as follows

Second, test Tomcat operation

Note That the webapps directory of a later version of Tomcat does not contain any content, which means that the default welcome page of Tomcat cannot be accessed. -i: Runs the container in interactive mode, usually with -t. -t: reassigns a pseudo-input terminal to the container. It is usually used together with -i.

docker run -itd -p 8080:8080 tomcat
Copy the code

Verify whether to start

1. If docker ps looks at the container that is currently running, if the following is displayed, it means that it has been successfully started, or IP +9999 (self-mapped) access



2. If the startup fails and the figure above is not displayed, the Docker logs container ID (which is returned after the docker run command is executed) is used to view the logs

Create Dockerfile

FROM tomcat:8.0
RUN rm -rf /usr/local/tomcat/webapps/* ADD ./server.xml /usr/local/tomcat/conf/ ENV TZ=Moran/bj RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo  ${TZ} > /etc/timezone CMD ["catalina.sh", "run"]Copy the code

Prepare server.xml

You can download a Tomcat copy of this file



Adding configuration Items

6. Upload server. XML Dockerfile to Linux server

7. Execute docker build compilation

Note img-tomcat-server:0.1 (image name) name followed by a space followed by a. Perform a Dockerfile lookup on behalf of the current directory

docker build -t image-tomcat . compileCopy the code

View the generated image file

9. Start Tomcat

docker run -d -v /blog/images:/data/ -p 9999:8080 --name img-tomcat-server image-tomcat
Copy the code

At this point, /blog/images has been mounted to the internal directory of the container. At this point, external Linux uploads the image and the Internet access is normal

Write at the end, thanks for the likes

Welcome to follow my wechat public account [Village of the Apes] \

To talk about Java interview and my wechat further communication and learning, wechat mobile search [codeYuanzhicunup] can be added if there are related technical problems welcome to leave a message to discuss, the public number is mainly used for technology sharing, including often meet test analysis, as well as source code interpretation, micro service framework, technical hot spots, etc..