This article documents several different Web server deployments, and the process is pretty much the same.

Technical summary: 1, choose mirror, the smaller the recommended volume, the better. Identify the host directory and mount it to the directory where the container holds the HTML files. 2. You can copy the HTML file to the image and run it again, but this is not convenient. 3. Contents in container:

  • Nginx:/usr/share/nginx/html
  • HTTPD:/usr/local/apache2/htdocs/
  • Tomcat:/usr/local/tomcat/webapps/ROOT
  • PHP:/var/www/

Nginx deployment

Important point: Choose nginx: Alpine version, small size.

Docker – compose documents:

version: "2"
services:
  nginx_all:
    image: nginx:alpine
    container_name: nginx_all
    volumes:
      - $PWD/nginx:/etc/nginx
    ports:
      - 8080:80
    networks:
      - mywebsite
  web1:
    image: latelee/nginx
    container_name: web1
    volumes:
      - $PWD/html1:/usr/share/nginx/html
    ports:
      - 8081:80
    networks:
      - mywebsite

  web2:
    image: latelee/nginx
    container_name: web2
    volumes:
      - $PWD/html2:/usr/share/nginx/html
    ports:
      - 8082:80
    networks:
      - mywebsite
networks:
    mywebsite:
      driver: bridge
Copy the code

Home page example:

cat XX/index.html
<html>
  <body>
    <h2>hello world</h2>
  </body>
</html>
Copy the code

httpd

HTTPD is actually Apache.

version: "2"
services:
  web1:
    image: latelee/httpd
    container_name: web1
    volumes:
      - $PWD/html1:/usr/local/apache2/htdocs/
    ports:
      - 8081:80
    networks:
      - mywebsite
  web2:
    image: latelee/httpd
    container_name: web2
    volumes:
      - $PWD/html2:/usr/local/apache2/htdocs/
    ports:
      - 8082:80
    networks:
      - mywebsite
networks:
    mywebsite:
      driver: bridge
Copy the code

tomcat

Version: '2' services: tomcat: image: tomcat:8.0.51-jre8-slim Container_name: tomcat #restart: always volumes: - $PWD/webapps:/usr/local/tomcat/webapps/ROOT ports: - "8080:8080"Copy the code
$ cat webapps/index.php
<html>
  <body>
    <h2>THis is tomcat test</h2>
    <p> PHP </p>
    <p> 2018 5 5 </p>
  </body>
</html>
Copy the code

php

Version: "2" services: PHP: image: PHP :7.2.7-apache container_name: PHP restart: always volumes: - ./www:/var/www/ ports: - 5000:80Copy the code