转载、翻译自 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. [补档][COGS 426]血帆海盗

    [COGS 426]血帆海盗 题目 传送门:http://cogs.pro/cogs/problem/problem.php?pid=426 随着资本的扩大,藏宝海湾贸易亲王在卡利姆多和东部王国大陆各 ...

  2. textarea的换行符处理以及正确的在Html中显示

    个人不太喜欢在页面做过多的逻辑处理,贴出java的处理方式 /** * Html转换为TextArea文本 * @return */ public static String HtmlToText(S ...

  3. 社群系统ThinkSNS V4.5.29 APP更新发布,新增用户认证及系统消息

    社群系统ThinkSNS V4版本移动端APP将于7月29日更新发布,本次更新修复部分bug,最主要是增加了移动端APP的用户认证功能,以及添加了系统消息,为V4.5.29版本发布.这两个功能PC端的 ...

  4. sqlite数据库之简单操作

    一 sqlite介绍 Sqlite是一种嵌入式数据库,类似于一个文件系统,是跟程序在一起的.跟mysql等数据库程序跟数据分离是不一样的. 应用场景:常用于保存本地配置,类似于本地文件系统,因此他内嵌 ...

  5. MATLAB中多行注释以及取消的快捷键

    多行注释:Ctrl+R 取消注释:Ctrl +T

  6. msbuildtoolspath is not specified for the toolsversion xx

    本地先是安装的vs2015,由于项目需求又安装了vs2008,在用vs2008打开.csproj工程文件,出现了上图的错误. 这一般是由于安装了vs2015和vs2008冲突产生的问题. 解决方案: ...

  7. Go语言结构体(struct)

    Go 语言结构体 Go 语言中数组可以存储同一类型的数据,但在结构体中我们可以为不同项定义不同的数据类型. 结构体是由一系列具有相同类型或不同类型的数据构成的数据集合. 结构体表示一项记录,比如保存图 ...

  8. ubuntu中安装搜狗输入法

    1.查看系统中是否安装fcitx,libss2-1的依赖包,查看命令 dpkg -I | grep fcitx  dpkg -I | grep libssh 没有安装的可以如下图命令安装 2.接下来我 ...

  9. Android MediaCodec硬编兼容性测试方案

    作者:阿宝 更新:2016-08-15 来源:彩色世界(https://blog.hz601.org/2016/08/15/android-mediacodec-hardcode-compatibil ...

  10. BYS推荐MS前端PhoneCall面试问题整理-2

    JS:1. 如何为一个已有的对象加一个新的方法,Prototype,这个不仅要知道,还要用过,写过 2. Angular和Ember比较的优势或不同点在哪里 3. null和undefined的区别, ...