Home > Operation and Maintenance > Docker > How to correctly deploy web projects with docker

How to correctly deploy web projects with docker

王林
Release: 2020-11-05 17:13:02
forward
5773 people have browsed it

How to correctly deploy web projects with docker

The specific steps are as follows:

(Recommended tutorial: docker tutorial)

1: Create a directory dock at will and be ready The following files:

How to correctly deploy web projects with docker

2. Write Dockerfile, through which you can quickly build a docker image

vi  Dockerfile
Copy after login

Add the following configuration

FROM centos
MAINTAINER this is dock image <jsh>
ADD jdk1.8.0_191 /usr/local/java
ENV JAVA_HOME /usr/local/java
ENV JAVA_BIN /usr/local/java/bin
ENV JRE_HOME /usr/local/java/jre
ENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/bin
ENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar
ADD apache-tomcat-8.5.40 /usr/local/tomcat8
ENTRYPOINT ["/usr/local/tomcat8/bin/catalina.sh","run"]
ADD ./manager.war /usr/local/tomcat8/webapps
EXPOSE 8080
Copy after login

Explanation:

(1) FROM centos means to obtain the centos basic image from the docker official warehouse
(2) ADD jdk1.8.0_191 /usr/local/ will be in the current directory (same level as Dockerfile directory) to the /usr/local/ of the image
(3) ENV JAVA_HOME /usr/local/jdk1.8.0_191 Set Java environment variables
(4) EXPOSE 8080 The port exposed to the outside world for convenience External access
(5) CMD /usr/local/tomcat8/bin/catalina.sh run command is executed after the container is running. If there are multiple CMDs, only the last one is valid.

3. Build the image

Command:

docker build -t dock .
Copy after login

(space after dock.) Complete the automatic build

4. Run the container

Command:

docker run -d -p 8060:8080 dock
Copy after login

-d means running the container in the background and returns the container ID

-p Using port mapping, 8060:8080 means mapping the container's 8080 port to the host's 8060 port.

View all running containers

Command:

docker ps -all
Copy after login

5. Test deployment results IP:8060 If the tomcat page appears, it means the container was started successfully.

The above is the detailed content of How to correctly deploy web projects with docker. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template