dongyuying1507 2018-09-24 23:44
浏览 425

无法从外部主机访问Docker部署的映像

So I have a Go application that I am deploying to a EC2 instance with Ansible and Jenkins pipeline as a Docker image. I have an image that I can access from outside the host using the IP address and the port number, 8080, using Postman. When I deploy a new image I cannot get a response using the ip address and port number. When I ssh into the server I can reach the endpoint using localhost and the port number. If I stop that image and start the first I can then reach it again.

What are the possible differences between these images that makes it so the endpoint can no longer be accessed via the ip address?

My Docker Compose File:

version: '2'
services:
  project-1:
    image: ...
    volumes:
      - /var/log:/var/log
    network_mode: host
    environment:
      - ...
    cpu_shares: 1236
    mem_limit: 2619m

My DockerFile:

FROM golang:1.10

WORKDIR /go/src/...
COPY . .

RUN go get -d -v ./...
RUN go install -v ./...

EXPOSE 8080-8080
CMD ./run.sh

I have also attempted removing network_mode from Docker Compose file and replacing it with ports as shown below with no success:

ports:
      - "0.0.0.0:8080:8080"
  • 写回答

2条回答 默认 最新

  • doufan9377 2018-09-25 01:16
    关注

    Make sure the container binds the port to the host port. In the container networking documentation you can read the following:

    By default, when you create a container, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host. Here are some examples.

    You can try running your container with the -p flag explained above:

    docker run -p 0.0.0.0:8080:80 your-container-image
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制