首页 > 其他分享 >Docker - Expose a port

Docker - Expose a port

时间:2023-09-22 21:35:23浏览次数:52  
标签:docker container Expose port nginx test our Docker 80

In order to access the nginx from our workstation, we would need to expose the port 80 from within the nginx container to our workstation. Let us first stop the container and recreate it to expose the container to our workstation:

% docker stop vigorous_chebyshev
vigorous_chebyshev
% docker rm vigorous_chebyshev
vigorous_chebyshev

The next step would be to run the nginx container once more, but now, we would need to ensure we expose port 80 of our nginx container to our workstation. At the same, we can try to use the -name flag so that we can control the name of the running
container. We can provide a shorter docker container name in order to make it easier to control the container.

zzh@ZZHPC:~$ docker run -p 80:80 -d --name=test nginx
f37c663dc7058d5c470bb8f0dee20f1da9cb0add6862d3c826abc8d7d6935ffe
zzh@ZZHPC:~$ docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                   PORTS                               NAMES
f37c663dc705   nginx         "/docker-entrypoint.…"   10 seconds ago   Up 9 seconds             0.0.0.0:80->80/tcp, :::80->80/tcp   test

Note that for the ports of our running container test, it exposes port 80 to our workstation via the following CIDR combination 0.0.0.0—which accepts traffic from any source at port 80. If we are to run the curl command from our workstation, we
will get the expected response of the welcome nginx page:

zzh@ZZHPC:~$ curl localhost
<!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>

With this, we can even add localhost to any browser on our workstation to view the nginx welcome page.

 

zzh@ZZHPC:~$ docker stop test
test
zzh@ZZHPC:~$ docker rm test
test

 

标签:docker,container,Expose,port,nginx,test,our,Docker,80
From: https://www.cnblogs.com/zhangzhihui/p/17723431.html

相关文章

  • docker安装jira
    阅读目录 1.下载镜像2.运行容器3.在MySQL中创建数据库4.在页面上访问jira并设置 回到顶部1.下载镜像#dockerpullxujianflying/jira:9.0.0#dockerpullxujianflying/mysql57:5.7回到顶部2.运行容器#运行jira,第一个8082为宿主端口,第二个为容器端口(不可修......
  • 如何设置SSH远程连接docker容器
    @https://blog.csdn.net/hwijew/article/details/88171749@https://blog.csdn.net/lhyhaiyan/article/details/128546411安装sshserverapt-getupdateapt-getinstallopenssh-server启动SSH服务sshstart查看SSH服务的状态servicesshstatus设置root密码和配置文件......
  • devexpress report 两半三联报表
    241mm 140mm三联换算成英尺如上  ......
  • 执行docker compose up -d报错 unknown shorthand flag: 'd' in -d
    执行dockercomposeup-d报错unknownshorthandflag:'d'in-d/usr/libexec/docker/cli-plugins/目录下没有docker-compose或者有docker-compose但执行dockerhelp显示InvalidPlugins:composefailedtofetchmetadata:exitstatus1 实际上是docker-compose未......
  • Docker Swarm + Harbor + Portainer 打造高可用,高伸缩,集群自动化部署,更新。
    DockerSwarm是Docker官方自带的容器编排工具,Swarm,Compose,Machine合称Docker三剑客。DockerSwarm对于中小型应用来说,还是比较方便,灵活,当然K8S对于大型项目在各方面有着明显的优势。技术选型需要针对公司实际情况选择,架构往往是一步一步随着业务变化升级演变而来,本文主要讲解Docke......
  • dockerfile编写总结
    编写Dockerfile文件1.dockerfile结构介绍  from基础镜像  maintainer维护者信息  run命令前加run  CMD容器启动时执行的操作,可以自定义脚本,也可执行系统命令  ENTRYPOINT容器启动时执行的操作,设置指令指定容器启动时执行的命令,可以追加命......
  • docker部署java项目
    1、首先你需要提前准备好jar包或者war包,并想办法放入Linux环境(或虚拟机)中;2、java项目的部署需要用到Tomcat或者Jetty,docker可以直接拉取他俩的镜像,这里以Tomcat为例:#:后面需要加上war或者jar对应的Tomcat版本,最好加上,#否则默认最新的版本--latest,会出现版本不兼容的问题d......
  • ABP + Vue Docker 部署
    #!/bin/bashecho"Welcometodockerbuild"echo""echo""ABP_HOST="abp/host"ABP_NG="abp/ng"cd..echo"Buildingdockerimage$ABP_HOST..."#cd到aspnet-core目录,eg:cd/data/apb/#将aspnet-......
  • Docker
    Ubuntu22.04全程root用户安装aptupdateaptinstall-yapt-transport-httpsca-certificatescurlgnupg-agentsoftware-properties-commoncurl-fsSLhttps://download.docker.com/linux/ubuntu/gpg|sudoapt-keyadd-add-apt-repository"deb[arch=amd64]https:......
  • Docker - Docker Desktopo
    ThereisareasonfortheneedforWindowsandMacuserstodownloadandworkwith DockerDesktopinsteadofworkingwithDockerbinarydirectly.Containerizationis moreofaLinuxtechnology,soitisnotavailableoutoftheboxforwindowsand macuse......