DOCKER学习(五)使用容器搭建一个web服务器

38 篇文章 2 订阅
22 篇文章 0 订阅

nginx Tags | Docker Hub

docker pull nginx:1.21.6-alpine
sudo docker container run nginx:1.21.6-alpine ls
sudo docker container run nginx:1.21.6-alpine cat /etc/os-release

ljx@ljx-desktop:~$ sudo docker  container run nginx:1.21.6-alpine ls -R -l /etc/nginx
/etc/nginx:
total 32
drwxr-xr-x    2 root     root          4096 Apr  5 09:00 conf.d
-rw-r--r--    1 root     root          1077 Jan 25 15:25 fastcgi.conf
-rw-r--r--    1 root     root          1007 Jan 25 15:25 fastcgi_params
-rw-r--r--    1 root     root          5349 Jan 25 15:25 mime.types
lrwxrwxrwx    1 root     root            22 Apr  5 09:00 modules -> /usr/lib/nginx/modules
-rw-r--r--    1 root     root           648 Jan 25 15:25 nginx.conf
-rw-r--r--    1 root     root           636 Jan 25 15:25 scgi_params
-rw-r--r--    1 root     root           664 Jan 25 15:25 uwsgi_params

/etc/nginx/conf.d:
total 4

ljx@ljx-desktop:~$ sudo docker container run nginx:1.21.6-alpine cat /etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
ljx@ljx-desktop:~$ sudo docker container run nginx:1.21.6-alpine  cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #access_log  /var/log/nginx/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   /usr/share/nginx/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$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$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;
    #}
}

ljx@ljx-desktop:~$ sudo docker container run nginx:1.21.6-alpine ls -R -l /usr/share/nginx/html
/usr/share/nginx/html:
total 8
-rw-r--r--    1 root     root           497 Jan 25 15:25 50x.html
-rw-r--r--    1 root     root           615 Jan 25 15:25 index.html

 

ljx@ljx-desktop:~$ sudo docker container run --name myweb -d -p 8088:80 nginx:1.21.6-alpine
d6dc3b46893b147a27404748afb89ca9e3daa3c55dc82dd629d9d89ca2cc57d4

 

ljx@ljx-desktop:~$ sudo docker container ls
CONTAINER ID   IMAGE                 COMMAND                  CREATED              STATUS              PORTS                                   NAMES
d6dc3b46893b   nginx:1.21.6-alpine   "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:8088->80/tcp, :::8088->80/tcp   myweb

 

ljx@ljx-desktop:~$ curl http://127.0.0.1:8088
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 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>

本地安装了nginx的浏览器输入http://127.0.0.1:8080是假的

输入本机ip:8080

验证方法如下

ljx@ljx-desktop:~$ sudo docker container stop myweb
myweb

打不开就对了

删除指定容器 

ljx@ljx-desktop:~$ sudo docker container rm -f myweb
myweb

 删除所有容器

ljx@ljx-desktop:~$ sudo docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
043caf8743255026521d045942efb8efd8fe03355bf73f960b3577d66df47766
00d80ab269c69210b88b59c4b55cff47b59a343bc8768c35a2e539937e560774
9aeec13aaeaaeaf8e6672412683f8c10643ddf77bd9853074d0554ca38e8e7a9
2b2c7b85ecbe56ca7011dfdc6688fc3cc7796a3894e230da992f98d9d202b25c
e90df885746bd388b685ea521bf8d965e1e4f071ebc39af47ce33404199e07a8
fc381165d64e275cb05b59d4b7545c393a527a1dd3d8d35bb85a0a36e2201a87
9d2250be426ee778540864ce0300b9e01e1919181a5a9f7f70ce30c6a9e7a9de
7f1c7a1fd90a56d6c5ca8edc2ec9cbe8141f0fa516ba937be996df83036a6b49
207ec85f5e0fca15abf975e832e138773ac73ab0700306ec389d636aa95ae5d3
2d4af0f4ddbd60b949f7a8f339c046be19293f39263ff930c70d297dfdad4dc5
8bbc494bbe63b9046074fa7a1a8ecc755f29800e0a11e6d8e8ca9d132814ecc0
8e85584aae5c71e4909703c9ff9e3792642907907a98986962ca6aa5c2a1e7e1
057a444dadb95a43bc63a0a989e67932e109d1da912c65b2c6665f1f3eb7856a
c4767b9b0bdd587f42eb004535b6254829f9ae1234e0c2e72b912dcf124da9c4
0ab51064fc6b4f49acafd04ecca71ec12baaa49ea209ee426cb64d2d4695620e
ce4de0b85a1b9c28b2a765f15c61a076bba85f47f74c848945973f3cff8126c3
a74f93c5b0b7d40ab3c98ee0a2675611d0d2af456faabbb8303d49617238505f
ebd2dca06622928948a55df5230ca5269a48414e90cc59ace5812f7331bb2ba8
7a26c023e76858822e59b2abf28e780f8e8e9ec1c5d5bccdc72b67eae306ca99
f8d92462c3e01d9c5232022bd502c07c13975d4b09aa024d63cec1d5ee1615dd
34cd2f082a27d248b5aa9760f80470cae5dea494edbfe6d876ad2f8fe6e802dc
c9d5241a205203b4d277ff5ecc8647f3ce23ffdd533112dae3cd5bab0bce9415
554dd0e4434c22c43a432b28c3cb22c95680db3f81cf3dd0fc7d5e2bdb810a16
8e16317ea411b16e3776807a7aeb4b08120734b211e9ec95c85c40d56e7106fe
66f73833411a423056305b726843f965b25952859e7a2dfb7e6747f9804cae85
d086c1f4a196dba46184eec8303a262ce42beed4e66a1aa0eaf0589108b919e3
181d39f1032fb813b8a84df19da26e774182c5371883debd14587b978444130c
efaf302a82428da2a6de5255ed9570ea02ed5eadb9bb079f23451fdd34de77d6
e22edfe4f82f9d8584c7d6bc656d05bc5d52dc279c381bfb442ba340a2e2e134
6a96b37f5df3be17a1ae9336c66283c2769631f77f29b0faf72b98acc2c8c122
b15f17441cd897b43f55bdac679b67909b2c3c5e2def6420d8b0f3a1a27e540e
666d188d797cffe22f823d37e20a054291d567c125f4cf1f56dccd4ef85f47fe
ff4f3b2ae5402dcb1b585b2c80aeae1e4290018cc6f59acd6d517686a76db1d1
7172f8853c04e508cfaaca1d1862d59a35161faeafa736640a97a16d788fddc8
ea55d4013a3c977e7e76fd5e5095fefabd2881ecad54e403657795f16943296c
67a1818483223b844ced3f7d26c498989e9aa666804675513b78794dc1fae17a
602bc42083f1c1cc01d98dc210ae5aca97811981f0f8646ae1c336a32507b879
a64cbe2211fef5f714bd08c5f62ae472f60c20a69fa04c2607beffe3495b534d
74d1058f01417e2bc044bc55379d5a66392654349049b25de26a65851c92eab1

Total reclaimed space: 32.09MB

 

ljx@ljx-desktop:~/myweb$ sudo docker container run --name myweb -d -p 8088:80 -v /home/ljx/myweb:/usr/share/nginx/html:ro nginx:1.21.6-alpine
7b675279025cdd900e8e9b3aba38ef10f8e4c7998fd13a0e4789a828d76b5673
ljx@ljx-desktop:~/myweb$ curl http://你的ip地址:8088
<h1>hello docker my name is china.</h1>
ljx@ljx-desktop:~/myweb$ curl http://127.0.0.1:8088
<h1>hello docker my name is china.</h1>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无证驾驶梁嗖嗖

让我们解决Jetson使用问题

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值