• 10_光速学会docker用法:80分钟一口气学完docker+k8s!带你掌握docker+k8s所有核心知识点,全程干货,无废话!


    启动第一个docker容器 

    1. #1、获取镜像
    2. #2、运行镜像,生成容器,应用就跑在了容器中。

    Nginx web服务器,运行处一个80端口的网站

    1. #在宿主机上,运行Nginx
    2. 1、开启服务器
    3. 2、在服务器上安装好运行Nginx所需的依赖关系
    4. 3、安装nginx yum install nginx -y
    5. 4、修改ngixnp配置文件
    6. 5、启动nginx
    7. 6、客户端访问nginx
    8. 比较耗时。。。。。。。。。。。

    如果让你用docker运行nginx,该怎么玩?

    1. 1、获取镜像,获取是从配置好的dcoker镜像网站中,去拉取nginx镜像
    2. #先搜索一下,镜像文件,是否存在
    3. [root@Hadoop2 ~]# docker search nginx
    4. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    5. nginx Official build of Nginx. 18996 [OK]
    6. unit Official build of NGINX Unit: Universal Web … 12 [OK]
    7. nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 121
    8. nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 79
    9. nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 33
    10. nginx/unit NGINX Unit is a dynamic web and application … 64
    11. nginxinc/nginx-s3-gateway Authenticating and caching gateway based on … 2
    12. nginx/nginx-ingress-operator NGINX Ingress Operator for NGINX and NGINX P… 1
    13. nginxinc/amplify-agent NGINX Amplify Agent docker repository 1
    14. nginx/nginx-quic-qns NGINX QUIC interop 1
    15. nginxinc/ingress-demo Ingress Demo 4
    16. nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 103
    17. nginxproxy/acme-companion Automated ACME SSL certificate generation fo… 123
    18. bitnami/nginx Bitnami nginx Docker Image 173 [OK]
    19. bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 29 [OK]
    20. ubuntu/nginx Nginx, a high-performance reverse proxy & we… 98
    21. nginxinc/nginmesh_proxy_debug 0
    22. nginxproxy/docker-gen Generate files from docker container meta-da… 12
    23. nginxinc/mra-fakes3 0
    24. kasmweb/nginx An Nginx image based off nginx:alpine and in… 6
    25. rancher/nginx-ingress-controller 11
    26. nginxinc/ngx-rust-tool 0
    27. nginxinc/mra_python_base 0
    28. nginxinc/nginmesh_proxy_init 0
    29. rancher/nginx-ingress-controller-defaultbackend 2
    30. [root@Hadoop2 ~]#
    31. #拉取,下载镜像
    32. [root@Hadoop2 ~]# docker pull nginx
    33. Using default tag: latest
    34. latest: Pulling from library/nginx
    35. 360eba32fa65: Pull complete
    36. c5903f3678a7: Pull complete
    37. 27e923fb52d3: Pull complete
    38. 72de7d1ce3a4: Pull complete
    39. 94f34d60e454: Pull complete
    40. e42dcfe1730b: Pull complete
    41. 907d1bb4e931: Pull complete
    42. Digest: sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
    43. Status: Downloaded newer image for nginx:latest
    44. docker.io/library/nginx:latest
    45. [root@Hadoop2 ~]#
    46. #查看本地的docker镜像有那些
    47. [root@Hadoop2 ~]# docker image ls
    48. REPOSITORY TAG IMAGE ID CREATED SIZE
    49. nginx latest f5a6b296b8a2 5 days ago 187MB
    50. [root@Hadoop2 ~]#
    51. #删除镜像的命令,其中使用了IMAGE ID,镜像ID;
    52. docker rmi f5a6b296b8a2
    53. #运行该nginx镜像,运行出具体的容器,然后这个容器中就可以跑一个nginx服务了;
    54. #运行镜像的命令,参数如下
    55. docker run 参数 镜像的名字/ID
    56. # -d后台运行容器
    57. # -p 80:80 端口映射,宿主机端口:容器内端口。若访问宿主机某个端口,相应的就会访问容器中对应端口。
    58. docker run -d -p 80:80 nginx
    59. #运行结果如下,docker run命令,会返回一个容器的id
    60. [root@Hadoop2 ~]# docker run -d -p 80:80 nginx
    61. 00d67544a8726e38459036279a1c68839ec82f47fa3d49d95fb5cdd7b806239c
    62. [root@Hadoop2 ~]#
    63. #查看容器是否在运行
    64. [root@Hadoop2 ~]# docker ps
    65. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    66. 00d67544a872 nginx "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, :::80->80/tcp great_mayer
    67. [root@Hadoop2 ~]#
    68. #可以尝试停止容器,看下结果
    69. docker stop 容器ID
    70. #停止具体的容器进程
    71. [root@Hadoop2 ~]# docker stop 00d67544a872
    72. 00d67544a872
    73. [root@Hadoop2 ~]#
    74. #查看看存在的进程
    75. [root@Hadoop2 ~]# docker ps
    76. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    77. [root@Hadoop2 ~]#
    78. docker stop

     

     查看端口占用情况

    1. [root@Hadoop2 ~]# netstat -tunlp
    2. Active Internet connections (only servers)
    3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    4. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 798/rpcbind
    5. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2097/dnsmasq
    6. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1211/sshd
    7. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1209/cupsd
    8. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1403/master
    9. tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2144/sshd: root@pts
    10. tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 6197/sshd: root@pts
    11. tcp6 0 0 :::111 :::* LISTEN 798/rpcbind
    12. tcp6 0 0 :::22 :::* LISTEN 1211/sshd
    13. tcp6 0 0 ::1:631 :::* LISTEN 1209/cupsd
    14. tcp6 0 0 ::1:25 :::* LISTEN 1403/master
    15. tcp6 0 0 ::1:6010 :::* LISTEN 2144/sshd: root@pts
    16. tcp6 0 0 ::1:6011 :::* LISTEN 6197/sshd: root@pts
    17. udp 0 0 192.168.122.1:53 0.0.0.0:* 2097/dnsmasq
    18. udp 0 0 0.0.0.0:67 0.0.0.0:* 2097/dnsmasq
    19. udp 0 0 0.0.0.0:68 0.0.0.0:* 6198/dhclient
    20. udp 0 0 0.0.0.0:111 0.0.0.0:* 798/rpcbind
    21. udp 0 0 127.0.0.1:323 0.0.0.0:* 818/chronyd
    22. udp 0 0 0.0.0.0:972 0.0.0.0:* 798/rpcbind
    23. udp 0 0 0.0.0.0:33872 0.0.0.0:* 809/avahi-daemon: r
    24. udp 0 0 0.0.0.0:5353 0.0.0.0:* 809/avahi-daemon: r
    25. udp6 0 0 :::111 :::* 798/rpcbind
    26. udp6 0 0 ::1:323 :::* 818/chronyd
    27. udp6 0 0 :::972 :::* 798/rpcbind
    28. [root@Hadoop2 ~]#
    29. 运行后
    30. [root@Hadoop2 ~]# netstat -tunlp
    31. Active Internet connections (only servers)
    32. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    33. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 798/rpcbind
    34. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6464/docker-proxy
    35. tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2097/dnsmasq
    36. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1211/sshd
    37. tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1209/cupsd
    38. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1403/master
    39. tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2144/sshd: root@pts
    40. tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 6197/sshd: root@pts
    41. tcp6 0 0 :::111 :::* LISTEN 798/rpcbind
    42. tcp6 0 0 :::80 :::* LISTEN 6471/docker-proxy
    43. tcp6 0 0 :::22 :::* LISTEN 1211/sshd
    44. tcp6 0 0 ::1:631 :::* LISTEN 1209/cupsd
    45. tcp6 0 0 ::1:25 :::* LISTEN 1403/master
    46. tcp6 0 0 ::1:6010 :::* LISTEN 2144/sshd: root@pts
    47. tcp6 0 0 ::1:6011 :::* LISTEN 6197/sshd: root@pts
    48. udp 0 0 192.168.122.1:53 0.0.0.0:* 2097/dnsmasq
    49. udp 0 0 0.0.0.0:67 0.0.0.0:* 2097/dnsmasq
    50. udp 0 0 0.0.0.0:68 0.0.0.0:* 6198/dhclient
    51. udp 0 0 0.0.0.0:111 0.0.0.0:* 798/rpcbind
    52. udp 0 0 127.0.0.1:323 0.0.0.0:* 818/chronyd
    53. udp 0 0 0.0.0.0:972 0.0.0.0:* 798/rpcbind
    54. udp 0 0 0.0.0.0:33872 0.0.0.0:* 809/avahi-daemon: r
    55. udp 0 0 0.0.0.0:5353 0.0.0.0:* 809/avahi-daemon: r
    56. udp6 0 0 :::111 :::* 798/rpcbind
    57. udp6 0 0 ::1:323 :::* 818/chronyd
    58. udp6 0 0 :::972 :::* 798/rpcbind
    59. [root@Hadoop2 ~]#

  • 相关阅读:
    文本处理的应用和编码文本历史
    如何找出电脑内的重复文件,查找电脑磁盘重复文件的方法
    Linux安装MySQL8.0服务
    MAYA粒子基础_场
    在 WPF 客户端实现 AOP 和接口缓存
    残差网络为什么有效
    Springboot 文件下载代码
    react嵌套路由
    DPDK ACL算法介绍(一)
    Apache Doris 整合 FLINK 、 Hudi 构建湖仓一体的联邦查询入门
  • 原文地址:https://blog.csdn.net/ninety_two/article/details/132854998