转载、翻译自 https://stackoverflow.com/questions/44014698/docker-failed-to-connect-to-localhost-port-4000-connection-refused

按照Docker的安装指导进行操作时,在Get Started, Part 2: Containers这一章,遇到如下问题。

(where you can check up the link here => https://docs.docker.com/get-started/part2/#run-the-app)

我使用了和示例中一致的 Dockerfile, requirements.txt

$ ls
app.py Dockerfile requriements.txt

Dockerfile的内容:

FROM python:2.7-slim
WORKDIR /app
ADD . /app
RUN pip install -r requriements.txt
EXPOSE 80
ENV NAME World
CMD ["python", "app.py"]

三个文件的内容和安装指导中的完全一致。使用如下指令建立镜像也成功了。

All 3 files have file content/code exactly same as the tutorial also. I was able to build image registry with this command

$ docker build -t friendlyhello .

一切看起来很正常,生成了frindlyhello的镜像,可以通过以下指令查看镜像

$ docker images

REPOSITORY TAG IMAGE ID CREATED

friendlyhello latest 82b8a0b52e91 39 minutes ago

python 2.7-slim 1c7128a655f6 5 days ago

hello-world latest 48b5124b2768 4 months ago

运行docker,将80端口映射到4000端口

$ docker run -d -p 4000:80 friendlyhello

使用docker ps指令检查运行状态

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
c1893f7eea9f friendlyhello "python app.py" 15 minutes ago Up 16 minutes

官方的指导手册说,可以在浏览器中输入地址 http://localhost:4000 来检测docker是否运行

可惜我无法连接到localhost

$ curl http://localhost:4000
curl: (7) Failed to connect to localhost port 4000: Connection refused

//------------------------------------------------------------------------------------------------------------------------------------

解决方案

查询docker-machine使用的默认IP

$  docker-machine ip default

使用查询到的IP在浏览器中

http://.......:4000

或使用curl指令

$  curl http://$(docker-machine ip default):4000

Docker - Failed to connect to localhost port 4000: Connection refused的更多相关文章

  1. Ubuntu下 ssh : connect to host localhost port 22:Connection refused

    Ubuntu下测试ssh时使用ssh localhost 命令,出现错误提示connect to host localhost port 22:Connection refused 造成这个错误的原因 ...

  2. 运行Hadoop start-all.sh遇到的错误ssh: connect to host localhost port 22: Connection refused

    ssh: connect to host localhost port 22: Connection refused 我的情况是ssh server没装,查看方法: ps -e |grep ssh 1 ...

  3. ssh: connect to host localhost port 22: Connection refused

    1.hadoop安装好之后,执行ssh localhost无法执行, 提示“ssh: connect to host localhost port 22: Connection refused”. 2 ...

  4. 新手git: ssh: connect to host localhost port 22: Connection refused

    由于gitlab上要git pull或者git clone,可是每次都出现这个问题.之前偶尔出现这个问题.可是仅仅是偶尔.这是为什么呢?然后就開始搜索网上的解决方式了. 这个问题搜索网上非常多答案.可 ...

  5. ssh本机失败(ssh: connect to host localhost port 22: Connection refused)

    ssh本机失败(ssh: connect to host localhost port 22: Connection refused) 一. 问题描述 之前一直在服务上使用宝塔面板, 今天突发奇想, ...

  6. ubuntu安装配置ssh-connect to host localhost port 22: Connection refused

    在安装ssh,经常出现 ssh: connect to host localhost port 22: Connection refused 从以下几点去检查: 1.是否安装ssh-server: 打 ...

  7. mac connect to host localhost port 22: Connection refused

    在Mac OS X 10.10.5学习hadoop的过程中,输入命令ssh localhost得到 ssh: connect to host localhost port : Connection r ...

  8. ssh: connect to host localhost port 22: Connection refused 问题

    错误原因:1.sshd 未安装2.sshd 未启动 3.防火墙 4需重新启动ssh 服务 解决方法:1.确定安装sshd: $ sudo apt-get install openssh-server ...

  9. 使用ssh localhost命令,发生异常ssh: connect to host localhost port 22: Connection refused

    使用"ssh localhost"命令,失败: 问题分析如下: 出现这个问题是因为Ubuntu默认没有安装openssh-server.检查是否安装了openssh-server, ...

随机推荐

  1. 14. leetcode 383. Ransom Note

    Given an arbitrary ransom note string and another string containing letters from all the magazines, ...

  2. 华为服务器Linux在线做RAID方法

    背景概述 最近维护大数据的一些主机,大概有3k+的数目,有很大一部分是华为的服务器,大部分是12块数据盘,单盘做RAID0来存放数据,但是通常硬件是不可靠的,磁盘损坏是常态, 然而磁盘损坏进行定位更换 ...

  3. angular select 遍历使用ng-option绑定的时候下面多出一个空白的option处理方法

    只需要在select中加入一个 <option value="" selected hidden></option>

  4. Shell Script编程——USB挂载/复制文件/查找文件/压缩文件

    PS:$引用变量的时候不要加空格.用了case,while的结构. main文件 #!/bin/bash chmod a+x changedate chmod a+x changemod chmod ...

  5. iOS - Block底层解析

    Block是iOS开发中一种比较特殊的数据结构,它可以保存一段代码,在合适的地方再调用,具有语法简介.回调方便.编程思路清晰.执行效率高等优点,受到众多猿猿的喜爱.但是Block在使用过程中,如果对B ...

  6. SQL语句查询某字段不同数据的个数(DISTINCT 的使用)

    今天做了一个题,学到了一个知识点: 有一个高速收费表VF,如下: 统计收费涉及的车辆有多少: SQL语句: SELECT  COUNT(DISTINCT  VchReg)  from  VF ; 其中 ...

  7. java核心技术卷一笔记(1)

    jdk是java开发工具包,里面包含了javac.jar.javadoc.java等工具,可以在bin目录中找到.有一个文件夹是jre,即jdk也包含了java运行环境.jre可单独安装,只是运行ja ...

  8. css的颜色表示,与透明度

    今天是第一天开始写博客.主要还是想着好记性不如烂笔头.每天学点什么就记下来,也防止以后再去百度.   今天主要是一些旧知识的整理,整理中看到原来写的代码对颜色的表示有用rgb的,有用rega的,有用# ...

  9. bootstrap modal 弹出效果

    window.showMsg = function (msg) { //显示悬浮窗 $("#autoCloseModal").modal("show") //设 ...

  10. C#多线程爬虫抓取免费代理IP

    这里用到一个HTML解析辅助类:HtmlAgilityPack,如果没有网上找一个增加到库里,这个插件有很多版本,如果你开发环境是使用VS2005就2.0的类库,VS2010就使用4.0,以此类推.. ...