docker port

2023-05-16

一 码云
https://gitee.com/login
用户名:cakin24

二 为什么要端口映射
在启动容器时,如果不配置宿主机器与容器的端口映射,外部程序是无法访问容器的,因为没有端口。

三 端口映射的指令是什么
docker指令:docker run -p ip:hostPort:containerPort redis
使用-p参数会分配宿主机的端口映射到容器。
IP表示主机的IP地址。
hostPort表示宿主机的端口。
containerPort表示容器的端口。

四 支持的格式有三种

ip:hostPort:containerPort:映射指定地址的指定端口到容器的指定端口(不常用)
如:127.0.0.1:3306:3306,映射本机的3306端口到容器的3306端口。
ip::containerPort:映射指定地址的任意端口到容器的指定端口。(不常用)
如:127.0.0.1::3306,映射本机的3306端口到容器的3306端口。
hostPort:containerPort:映射本机的指定端口到容器的指定端口。(常用)
如:3306:3306,映射本机的3306端口到容器的3306端口。

五 实战

[root@localhost ~]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
Digest: sha256:cd277716dbff2c0211c8366687d275d2b53112fecbf9d6c86e9853edb0900956
Status: Image is up to date for redis:latest
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
cakin24/test        0.2                 dea19e48db1f        5 hours ago         1.13MB
33                  0.1                 dea19e48db1f        5 hours ago         1.13MB
redis               latest              8f2e175b3bd1        6 days ago          107MB
clearlinux          latest              32685d114002        7 days ago          62.5MB
busybox             latest              6ad733544a63        7 days ago          1.13MB
alpine              latest              053cde6e8953        7 days ago          3.96MB
[root@localhost ~]# docker run -p 6379:6379 8f
1:C 11 Nov 06:35:31.913 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 11 Nov 06:35:31.914 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 11 Nov 06:35:31.914 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 11 Nov 06:35:31.917 * Running mode=standalone, port=6379.
1:M 11 Nov 06:35:31.917 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 11 Nov 06:35:31.917 # Server initialized
1:M 11 Nov 06:35:31.917 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 11 Nov 06:35:31.920 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 11 Nov 06:35:31.920 * Ready to accept connections
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
4402a5aa9e04        8f                  "docker-entrypoint..."   36 seconds ago      Up 34 seconds              0.0.0.0:6379->6379/tcp   romantic_wiles
cde922a07f9a        redis               "docker-entrypoint..."   9 minutes ago       Exited (0) 2 minutes ago                            optimistic_bhaskara
1fb916fb0e13        6a                  "sh"                     4 hours ago         Exited (0) 2 hours ago                              hello2
9fb1ff8de577        6a                  "sh"                     4 hours ago         Up 2 hours                                          hello
[root@localhost ~]# docker port 44
6379/tcp -> 0.0.0.0:6379



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

docker port 的相关文章

随机推荐

  • Slack 消息回传

    Slack预留了回传接口 可以将报错 告警信息等回传到Slack频道里 https api slack com messaging webhooks
  • Postgres 最大连接数满了: remaining connection slots are reserved for non-replication superuser connections

    最近遇到链接pg数据库报错 xff1a remaining connection slots are reserved for non replication superuser connections 百度说 xff0c 是由于设置的最大
  • oracle游标:fetch和for循环游标

    1 fetch 显式的open close Declare Cursor cur Is Select xtwldm From xtm14 curRow cur Rowtype Begin Open Cur Loop Fetch cur In
  • .net {"已添加项。字典中的关键字:“**”所添加的关键字:“**”"}

    用户代码未处理 System ArgumentException HResult 61 2147024809 Message 61 已添加项 字典中的关键字 00 所添加的关键字 00 Source 61 mscorlib StackTra
  • docker: 为运行的container增加多个端口

    1 list all docker process and stop running container test01 docker ps a docker stop test01 2 commit the container docker
  • git prune, git remote prune, git fetch --prune 三者异同

    远程分支的3种状态 远程仓库确实存在分支dev本地版本库 xff08 git xff09 中的远程快照和远程分支建立联系的本地分支 git prune https git scm com docs git prune Prune all u
  • Jmeter_Non HTTP response code: java.net.SocketException

    error msg rc 61 span class hljs string 34 Non HTTP response code java net SocketException 34 span rm 61 span class hljs
  • SQL Server 数据库导入导出数据

    Data Micration between SQL Server Database 1 减少源数据库的导出数据 排除日志表数据 xff1a 日志表数据体积大且没有导出价值 精简掉备份表 xff1a 为了保证数据的安全 xff0c 一般会对
  • 程序员读书啦!!!

    成为Java顶尖程序员 xff0c 看这11本书就够了 xff1a http blog csdn net u012410733 article details 51869105 编程科普书籍推荐 xff1a http blog csdn n
  • Windows设置本地DNS域名解析Hosts

    DNS Domain Name System 域名系统 xff1a 为了加快定位IP地址的速度 将域名映射进行层层缓存的系统 目的 xff1a 互联网通过IP xff08 10 223 146 45 xff09 定位浏览器建立连接 xff0
  • 机器学习之缺失样本重采样策略

    1 引言 在机器学习领域中 对不均衡数据集进行建模是我们训练模型时经常遇到的挑战 比如在分类问题上 训练集上类别的平衡对模型建模起着重要作用 如果直接对类间不平衡的数据进行建模 xff0c 即数据集中存在少数类 xff0c 这样训练好的模型
  • aptitude与apt-get

    aptitude 与 apt get 一样 xff0c 是 Debian 及其衍生系统中功能极其强大的包管理工具 与 apt get 不同的是 xff0c aptitude 在处理依赖问题上更佳一些 举例来说 xff0c aptitude
  • js 冒泡排序、函数(function)

    一 冒泡排序 原理 数组中的元素两个两个进行比较 xff0c 如果前面的数大于后面的数就进行交换 xff0c 如果前面的数小于后面的数不交换位置 xff0c 后面的继续和下一个进行比较 整体代码 xff1a 冒泡排序 var arr 10
  • python 中Dict 转 Json

    最近在公司需要写个小工具 xff0c 运用到的python xff0c 然后需要将Dict转成Json 之前遇到转换Json失败 xff0c 然后以为复杂的Entity结构 xff0c 不能用Json的库Json dump xff0c 进行
  • Zabbix监控

    由于本人工作职责的一部分 xff0c 需要用Zabbix监控 xff0c 所以在此贴一下Zabbix监控 实在觉得Zabbix监控做的太牛掰 xff0c 先打Tag xff0c 周末再来补全
  • 看完23岁的我在干嘛之后有感

    现在我已经25岁了 xff0c 先说我23岁的时候吧 xff0c 23岁我在干嘛 xff0c 刚上研究生 xff0c 好像貌似一切都挺顺的 xff0c 考研成功 xff0c 进入北京比较好的一所大学读计算机 xff1b 然后是和前任分手 x
  • Libev源码解析

    最近在看libev源码 xff0c 算是对libev的源码有个比较清晰的了解 总共分3部分来介绍libev 1 Libev是什么 Libev是基于Reactor模式的一个高性能 xff0c 支持高并发的事件库 它本身不仅支持IO xff0c
  • Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面 .相机.录影机....

    Android开发之Intent跳转到系统应用中的拨号界面 联系人界面 短信界面 现在开发中的功能需要直接跳转到拨号 联系人 短信界面等等 xff0c 查找了很多资料 xff0c 自己整理了一下 安装已经存在的apk String file
  • C++ STL中判断list为空,size()==0和empty()有什么区别

    关于两个的区别 xff0c 首先size 61 61 0为bool表达式 xff0c empty 为函数调用 xff0c 这一点很明显 查看源代码 xff0c bool empty const return M node gt M next
  • docker port

    一 码云 https gitee com login 用户名 xff1a cakin24 二 为什么要端口映射 在启动容器时 xff0c 如果不配置宿主机器与容器的端口映射 xff0c 外部程序是无法访问容器的 xff0c 因为没有端口 三