转载、翻译自 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. JSP和El表达式和JSTL标签库使用

    核心标签库: <%@ page language="java" import="java.util.*" pageEncoding="utf-8 ...

  2. 使用Node.js调用阿里云短信的发送以及接收

    为了使用Node.js调用阿里云短信服务,我自己写了个npm包, 目前实现了: 使用Node.js调用阿里云短信服务,发送短信: 使用Node.js调用阿里云短信服务以及MNS服务,接收用户上行短信 ...

  3. ABP+AdminLTE+Bootstrap Table权限管理系统第一节--使用ASP.NET Boilerplate模板创建解决方案

    "abp是ASP.NET Boilerplate简称,是一个用最佳实践和流行技术开发现代WEB应用程序的新起点,它旨在成为一个通用的WEB应用程序框架和项目模板" abp官方网站: ...

  4. Aspose.Words关于域的应用

    #region 通过word域去插入相应的数据 /// <summary> /// 通过word域去进行指定位置替换数据 /// </summary> public void ...

  5. SpringBoot基础梳理

    1.入口类和@SpringBootApplication注解: SpringBoot通常有一个名为*Application的入口类,入口类里面有main方法,我们可以通过启动main方法启动sprin ...

  6. Java的代码风格

    1.Java文件的命名规则: . JAVA源文件的命名 JAVA源文件名必须和源文件中所定义的类的类名相同. 2. Package的命名 Package名的第一部分应是小写ASCII字符,并且是顶级域 ...

  7. 13. Roman to Integer【leetcode】

    Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within t ...

  8. MySQL binlog相关分析

    1.redolog.binlog的简单分析 图解:redolog和binlog机制 2.开启binlog及关注点 3.关注binlog的相关参数 4.binlog模式分析 5.关于binlog的使用 ...

  9. js的点表示法和方括号表示法

    最近发现了一个很好玩的js特性,就是任何可以用点表示法的语句,都可以同样用方括号表示法表示出来,就例如一下语句,三句都是可以实现的: document.body.innerHTML="tes ...

  10. 一步步学习操作系统(1)——参照ucos,在STM32上实现一个简单的多任务(“啰里啰嗦版”)

    该篇为“啰里啰嗦版”,另有相应的“精简版”供参考 “不到长城非好汉:不做OS,枉为程序员” OS之于程序员,如同梵蒂冈之于天主教徒,那永远都是块神圣的领土.若今生不能亲历之,实乃憾事! 但是,圣域不是 ...