首页 > 系统相关 >使用docker部署nginx服务

使用docker部署nginx服务

时间:2022-11-25 17:47:16浏览次数:35  
标签:ingress 部署 nginx 0088cd883947 docker root localhost

docker安装nginx

1.查找镜像

docker search命令查找,也可以去docker hub(https://hub.docker.com)上搜索!!!

[root@localhost ~]# docker search nginx
NAME                                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                                             Official build of Nginx.                        17733               [OK]                
linuxserver/nginx                                 An Nginx container, brought to you by LinuxS…   181                                     
bitnami/nginx                                     Bitnami nginx Docker Image                      143                                     [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   67                                      
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   22                                      [OK]
rancher/nginx-ingress-controller                                                                  11                                      
ibmcom/nginx-ingress-controller                   Docker Image for IBM Cloud Private-CE (Commu…   4                                       
bitnami/nginx-ldap-auth-daemon                                                                    3                                       
bitnami/nginx-exporter                                                                            3                                       
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in…   3                                       
rancher/nginx                                                                                     2                                       
vmware/nginx                                                                                      2                                       
rancher/nginx-ingress-controller-defaultbackend                                                   2                                       
rapidfort/nginx                                   RapidFort optimized, hardened image for NGINX   2                                       
circleci/nginx                                    This image is for internal use                  2                                       
wallarm/nginx-ingress-controller                  Kubernetes Ingress Controller with Wallarm e…   1                                       
vmware/nginx-photon                                                                               1                                       
bitnami/nginx-intel                                                                               1                                       
rapidfort/nginx-ib                                RapidFort optimized, hardened image for NGIN…   0                                       
ibmcom/nginx-ingress-controller-ppc64le           Docker Image for IBM Cloud Private-CE (Commu…   0                                       
rancher/nginx-conf                                                                                0                                       
rancher/nginx-ssl                                                                                 0                                       
continuumio/nginx-ingress-ws                                                                      0                                       
rancher/nginx-ingress-controller-amd64                                                            0                                       
ibmcom/nginx-ppc64le                              Docker image for nginx-ppc64le                  0                                       

2.下载镜像

[root@localhost ~]# docker pull nginx

3.运行测试

//-p表示暴漏端口 命令:-p:宿主机端口:容器内部端口
//将nginx01的80端口映射到宿主机的3344端口
[root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx
0088cd8839470a433f559547fbd7037fc43802b16e0f4da3aa3df1e61a5a8889
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
0088cd883947        nginx               "/docker-entrypoint.…"   15 seconds ago      Up 13 seconds       0.0.0.0:3344->80/tcp   nginx01
//本地访问刚才映射的3344端口测试
[root@localhost ~]# curl localhost:3344
<!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>

4.进入容器

[root@localhost ~]# docker exec -it nginx01 /bin/bash
root@0088cd883947:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@0088cd883947:/# cd /etc/nginx
root@0088cd883947:/etc/nginx# ls
conf.d    fastcgi_params    mime.types  modules  nginx.conf  scgi_params  uwsgi_params

5.停止容器服务

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
0088cd883947        nginx               "/docker-entrypoint.…"   30 minutes ago      Up 30 minutes       0.0.0.0:3344->80/tcp   nginx01
//使用stop命令停止
[root@localhost ~]# docker stop 0088cd883947
0088cd883947

停止服务后浏览器再访问会报错,因为刚才已经用stop命令将服务停止了。

 

 

 

以上,就是使用docker部署nginx的方法!部署其他应用则大同小异,多练习会熟能生巧!!!

附一张自己理解的端口暴露的概念,见下图:

 

标签:ingress,部署,nginx,0088cd883947,docker,root,localhost
From: https://www.cnblogs.com/yzq-top/p/16925520.html

相关文章

  • Nginx 编译安装
    Nginx编译安装安装环境:rocky8.0**安装前将防火墙和selinux关闭****文件中有注释的地方,复制时记得删除掉**官方包地址:http://nginx.org/en/linux_packages.html#......
  • docker搭建Elasticsearch、Kibana、Logstash 同步mysql数据到ES
    一、前言在数据量大的企业级实践中,Elasticsearch显得非常常见,特别是数据表超过千万级后,无论怎么优化,还是有点力不从心!使用中,最首先的问题就是怎么把千万级数据同步到Elasti......
  • 解决Centos7中docker无法从非官方库中pull镜像
    系统版本[root@bogon~]#cat/etc/redhat-release CentOSLinuxrelease7.1.1503(Core)  docker版本[root@bogon~]#docker--versionDockerversion1.7.1,build4......
  • centos7部署mpi和module环境
    1.概述本篇博客主要介绍在centos7.9部署和测试mpi并行程序开发环境,并通过module加载不同的环境。2.部署过程2.1安装mpich节点安装相关依赖环境:yum-yinstallgcc-g......
  • Linux部署kafka集群
    Linux部署kafka集群(亲测有效)原创 陈肖萧晓 若愚Linux 2022-11-2308:00 发表于山东收录于合集#linux7个#kafka1个#集群1个Linux部署kafka(亲测有效)网上有太......
  • docker,redis速拉
    记录docker快速拉取redis1.搜索dockersearchredis2.拉取dockerpullredis3.路径mkdir-p/home/redis/myredis/datacd/home/redis/myredis/4.配置vimmyredi......
  • nginx 开启 websock 线上支持
    WebSocket和HTTP虽然是不同协议,但是两者“握手”方式兼容。通过HTTP升级机制,使用HTTP的Upgrade和Connection协议头的方式可以将连接从HTTP升级为WebSocket。proxy_http_......
  • 更改docker存储路径
    docker默认存储路径是/var/lib/docker,占用服务器根分区。容易导致磁盘空间占满停止docker1systemctlstopdocker创建新的存储路径1mkdir/home/docker-p迁移......
  • docker中常用的命令
    一、docker的基础命令1.docker的帮助命令//命令docker--help[root@localhost~]#docker--helpUsage:docker[OPTIONS]COMMANDAself-sufficientruntime......
  • docker 网络
    1.Docker网络类型安装Docker时,它会自动创建三个网络,bridge(创建容器默认连接到此网络)、 none 、host。使用命令查看当前Docker所有的网络模式。[root@VM-4-13-centos......