转载、翻译自 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. Python实现单词查询&文件查找

    最近学C++ Primer,做到第十二章有个习题.要求针对英文文本,对于用户想搜索的单词,打印出该单词在文本中出现的总次数,单词所出现行号及对应的行内容:单词在一行内出现多次,只打印该行一次.C++的 ...

  2. 数据库中间件 Sharding-JDBC 源码分析 —— SQL 解析(三)之查询SQL

  3. Wamp之mysql密码故事

    注:有时候修改mysql密码会出现如下状况:密码改了,但新密码就是进不进去. 原因大概是语法错误.例如: >update user set password='hooray' where use ...

  4. 前端开发之css篇

    一.css简介 css(Cascading Style Sheets)层叠样式表,是一种为html文档添加样式的语言,主要有两个功能:渲染和布局.使用css主要关注两个点:查找到标签,属性操作 二.c ...

  5. VS2010 常见错误类型汇总

    开发路漫漫,尤其对于刚从事开发不久的新手来说,常常遇到一些稀奇古怪的错误,很是头疼,鉴于自己在开发过程中常遇到的几个错误做个分享,希望对大家有所帮助: 错误1: 在创建完win32的DLL后,编译时出 ...

  6. orakill和ALTER SYSTEM KILL SESSION详解

    --orakill和ALTER SYSTEM KILL SESSION详解[转]-----------------------------------------2013/11/05 一个用户进程偶尔 ...

  7. C/C++ 知识点---存储区

    C/C++ 知识点---存储区 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区.    栈,就是那些由编译器在需要的时候分配,在不需要的时候自动清楚的变量的存储 ...

  8. C#多线程的用法5-线程间的协作Monitor

    之前我们使用lock快捷方式,实现了多线程对同一资源的共享.在C#中lock实际上是Monitor操作的简化版本. 下面使用Monitor来完成之前的lock功能,你可以在此做一下对照: privat ...

  9. javascript如何创建一个换行节点

    换行节点和其他节点的创建方式一样,使用document.createElement("br");创建节点, 并使用parentNode.appendChild()将节点插入到相应的 ...

  10. bootstrap modal 弹出效果

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