转载、翻译自 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. 表达式求值(二叉树方法/C++语言描述)(三)

    二叉树方法求值对运算数处理的方法与栈方法求值不太相同,除了将字符串中的运算数转换为浮点类型外,还需要生成新的节点: void Calculator::dealWithNumber(char *& ...

  2. Linux Shell 1 - Print from terminal

    Two ways to print info from terminal - echo & printf - Echo a. Exclamation mark is supported in ...

  3. NYOJ--20--搜索(dfs)--吝啬的国度

    题意,N座城市有N-1条路,目的是找到哪个城市可以到目的城市 //NYOJ--search--吝啬的国度 #include<iostream> #include<vector> ...

  4. asp.net mvc项目远程发布到windows server服务器

    文章参考 自学MVC看这里——全网最全ASP.NET MVC 教程汇总 图文详解远程部署ASP.NET MVC 5项目 配置Web部署处理程序 设备及环境 一台装有windows server 201 ...

  5. 鄙人对constructor和prototype的总结

    在学习js面向对象过程中,我们总是对constructor和prototype充满疑惑,这两个概念是相当重要的,深入理解这两个概念对理解js的一些核心概念非常的重要.因此,在这里记录下鄙人见解,希望可 ...

  6. Jquery ztree树插件2

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  7. 01-artDialog4.1.7常用整理

    关闭弹出框的几种常见方法: 1,artDialog可以通过鼠标双击关闭对话框,esc关闭对话框等.为了在关闭对话框要执行某一方法,不能仅仅在弹框中的关闭按钮中写.这时提供了一个函数:close.无论在 ...

  8. SpringMVC创建HelloWorld程序

    1.IDE说明和依赖管理工具说明 开发工具:intellij idea 依赖管理使用:maven 2.创建maven工程 创建新的maven工程,并添加相应的文件夹,创建好的项目目录如下所示: 3.添 ...

  9. 禁止将http请求强制转换为https请求

    近期遇到一个问题,在谷歌浏览器里发起的http请求都会被转化为https请求,但在safari里面不会被转化,所以暂时只能用Safari浏览器进行调试,后来还查看了为什么http被强制转化为https ...

  10. .Net Core 2.0生态(4):Entity Framework Core 2.0 特性介绍和使用指南

    前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升级EF也发展到EF6.x,Entity Framework Core是一个支持跨平台的全新版本, ...