我的docker随笔21:web 服务器部署

本文记录几种不同的web服务器部署,其过程大同小异。

技术总结:
1、选择镜像,建议体积越小越好。确认宿主机目录,将其挂载到容器存放 html 文件的目录。
2、可以将 html 文件拷贝到镜像中重新运行,但此法不太方便。
3、容器内的目录:

  • nginx:/usr/share/nginx/html
  • httpd:/usr/local/apache2/htdocs/
  • tomcat: /usr/local/tomcat/webapps/ROOT
  • php:/var/www/

nginx部署

要点:选择nginx:alpine版本,体积小。

docker-compose 文件:

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

主页示例:

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

httpd

httpd实际是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

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"
$ cat webapps/index.php
<html>
  <body>
    <h2>THis is tomcat test</h2>
    <p> PHP </p>
    <p> 2018 5 5 </p>
  </body>
</html>

php

version: "2"
services:
  php:
    image: php:7.2.7-apache
    container_name: php
    restart: always
    volumes:
      - ./www:/var/www/
    ports:
      - 5000:80
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值