docker服务编排--docker-compose

摘要:
如果您看到此页面,则ginxWeb服务器已成功安装并工作。需要进一步配置。 在线文档和支持请参考nginx.org.商业支持可用nginx.com.感谢nginx.另一种方式--link mode#在后台运行alpine并将mynginx容器绑定到域名myngdockerrun dit--link mynginx:myngalpine825d4b3d221238bda2f29411fcae6d72fafb97d5002986660aa8c3b7cc501d99#安装curlapkaddurlfetchhttp://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gzfetchhttp://dl-cdn.alpinelux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz(1/4)安装证书(2/4)安装http2 libs(3/4)安装libcurl(4/4)安装urlExecutingbusybox-1.31.1-r9.triggerExecutinga-certificates-20191127-r1.triggerOK:7MiB-188packages#curlnginx image curlmyng˂!

根据哔哩哔哩视频【docker入门2】实战~如何组织一个多容器项目docker-compose进行学习

利用网站https://labs.play-with-docker.com/进行测试

第一步,安装nginx镜像

# 拉取nginx镜像
docker pull nginx
# 运行nginx容器
docker run -d -p80:80 --name mynginx nginx 
#容器ID
87702c4c192061036d731df8f533a82f20b972284b650a850adec3aba9580342
# 查看运行中的容器
docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
87702c4c1920        nginx               "nginx -g 'daemon of…"   24 seconds ago      Up 23 seconds       0.0.0.0:80->80/tcp   mynginx 
# 在容器中进行交互操作
docker exec -it mynginx /bin/bash
# 查看容器IP地址
cat /etc/hosts

127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.2	87702c4c1920

第二步:安装最小化Linux镜像alpine

# 拉取alpine镜像
docker pull alpine
# 安装curl
apk add curl
# curl nginx容器
curl 172.17.0.2

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
         35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

另外一种方式 --link方式

#后台运行alpine,并将mynginx容器绑定域名myng
docker run -dit --link mynginx:myng alpine   
825d4b3d221238bda2f29411fcae6d72fafb97d5002986660aa8c3b7cc501d99
# 安装curl
apk add curl

fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20191127-r1)
(2/4) Installing nghttp2-libs (1.40.0-r0)
(3/4) Installing libcurl (7.67.0-r0)
(4/4) Installing curl (7.67.0-r0)
Executing busybox-1.31.1-r9.trigger
Executing ca-certificates-20191127-r1.trigger
OK: 7 MiB in 18 packages
# curl nginx镜像
curl myng

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
         35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# 原理,增加了172.17.0.2      myng d2d78de2ad2f
cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2      myng d2d78de2ad2f
172.17.0.3      9688a42fec94

docker-compose方式

/Users/doubledumbao/docker-demo/compose-demo目录下,新建html目录,添加index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hello world nginx</title>
</head>
<body>
    <h1>hello world nginx!!!</h1>
</body>
</html>

/Users/doubledumbao/docker-demo/compose-demo/html目录下,添加test.php

<!DOCTYPE html>
<html>
<body>

<?php
echo "Hello World PHP!!!";
?>

</body>
</html>

/Users/doubledumbao/docker-demo/compose-demo/html目录下,添加mysql.php

<?php
$servername = "mysql";
$username = "root";
$password = "123456";
 
// 创建连接
$conn = new mysqli($servername, $username, $password);
 
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
echo "connected success !!!!!";
?>

/Users/doubledumbao/docker-demo/compose-demo目录下,新建conf目录

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        # location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        # }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
           fastcgi_pass   php:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
           include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

/Users/doubledumbao/docker-demo/compose-demo目录下,添加docker-compose.yml

version: '3'
services: 
    nginx:
        image: nginx:alpine
        ports: 
        - 80:80
        volumes: 
        - /Users/doubledumbao/docker-demo/compose-demo/html:/usr/share/nginx/html
        - /Users/doubledumbao/docker-demo/compose-demo/conf/nginx.conf:/etc/nginx/nginx.conf
    php:
        image: devilbox/php-fpm:5.2-work-0.89
        volumes: 
        - /Users/doubledumbao/docker-demo/compose-demo/html:/var/www/html
    mysql:
        image: mysql:5.6
        environment: 
        - MYSQL_ROOT_PASSWORD=123456

启动docker-compose

docker-compose up

打开浏览器,查看效果

# 查看nginx配置效果
http://localhost
# 查看php配置效果
http://localhost/test.php
# 查看mysql配置效果
http://localhost/mysql.php

免责声明:文章转载自《docker服务编排--docker-compose》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇匿名内部类的调用php-fpm和cgi,并发响应的理解以及高并发和多线程的关系下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

nginx 配置以及常用命令

windows下安装以及配置nginx http://jingyan.baidu.com/article/f3e34a12a9c1c3f5eb6535d4.html 1)下载地址: http://nginx.org 2)启动 解压至c: ginx,运行nginx.exe(即nginx -c conf ginx.conf),默认使用80端口,日志见文件夹C:...

JAVA多线程提高十三:同步集合类的应用

 1.引言   在多线程的环境中,如果想要使用容器类,就需要注意所使用的容器类是否是线程安全的。在最早开始,人们一般都在使用同步容器(Vector,HashTable),其基本的原理,就是针对容器的每一个操作,都添加synchronized来进行同步,此种方式尽管简单,但是其性能是非常地下的,所以现在已经不怎么使用了。人们普遍会使用并发的容器,在JDK1....

CmsTop 大众版运行环境搭建 (CentOS+Nginx+PHP FastCGI)

一、CentOS 5.5 操作系统的安装 操作系统这里我们仍采用 CentOS 5.5 来说明 Linux 下的 Nginx 安装与配置。关于CentOS的安装与注意事项请大家点击这里:(其中包含配置yum的步骤,因为我们接下来会使用到yum)。 二、准备工作 和Apache的配置相同,我们就来进行一些准备工作,譬如创建网站目录,日志目录等。然后安装服务器...

如何用Dockerfile构建镜像

Dockerfile构建镜像是以基础镜像为基础的,Dockerfile是一个文本文件,内容是用户编写的一些docker指令,每一条指令构建一层,因此每一条指令的内容,就是描述该层应当如何构建。 Dockerfile的基本指令有十三个,分别是:FROM、MAINTAINER、RUN、CMD、EXPOSE、ENV、ADD、COPY、ENTRYPOINT、VOL...

针对IE浏览器里面CSS的Bug解决方法

IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况。如外边距设置为10px, 而左侧则呈现出20px,解决它的方法是在浮动元素上加上display:inline;的样式,这样就可避免双倍边距bug。 3像素问题及解决办法 当使用float浮动容器后,在IE6下会产生3px的...

基于docker安装superset

    检查是否已安装docker(docker version)root@VM-32-248-ubuntu:~# docker versionClient: Version:      1.13.1 API version:  1.26 Go version:   go1.6.2 Git commit:   092cba3 Built:        T...