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

How to correctly deploy web projects with docker

王林
王林forward
2020-11-05 17:13:025715browse

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

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

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 .

(space after dock.) Complete the automatic build

4. Run the container

Command:

docker run -d -p 8060:8080 dock

-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

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete