无法让localhost连接到vagrant里面的docker

时间:2016-11-28 03:04:16

标签: go docker vagrant docker-compose

我正在尝试为GoLang构建一个本地开发环境。

我的环境将包含一个使用ubuntu的VirtualBox VM,而我在内部使用docker-compose来构建我的不同部分。

除了golang之外,我环境的所有其他部分都有效。

当我尝试获取一个简单的hello world HTTP响应时,它会在chrome内部返回“ERR_SOCKET_NOT_CONNECTED”。

我的流浪文件看起来像

Vagrant.configure("2") do |config|
  config.vm.box =  "ubuntu/trusty64"

  port = 3000
  config.vm.hostname = "vagrant-docker-example"
  config.vm.network(:forwarded_port, guest: port, host: port)
  config.vm.network(:forwarded_port, guest: 8080, host: 8080)
  config.vm.network(:forwarded_port, guest: 80, host: 4567)


  config.vm.provision :shell, inline: "apt-get update"
  config.vm.provision :docker
  config.vm.provision :docker_compose, env: { "PORT" => "#{port}" }, yml: ["/vagrant/docker-compose-base.yml","/vagrant/docker-compose.yml"], rebuild: true, project_name: "myproject", run: "always"
end

我的docker-compose文件看起来像

app:
  build: ./
  links:
    - redis
  ports:
    - "${PORT}:8080"

nginx:
    image: nginx:latest
    ports:
        - 80:80

最后我的docker文件看起来像

# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang

# Copy the local package files to the container's workspace.
ADD . $GOPATH/src/github.com/sinangedik/vagrant-docker-go-example

#Build
RUN go get github.com/tools/godep &&\
    cd $GOPATH/src/github.com/sinangedik/vagrant-docker-go-example &&\
    godep go build

#Give the ownership to daemon
RUN ["chown", "-R", "daemon", "."]
USER daemon
#Set the port
ENV PORT 3000
# Document that the service listens on port 8080.
EXPOSE 3000
CMD ["/go/src/github.com/sinangedik/vagrant-docker-go-example/vagrant-docker-go-example"]

我在这里做错了什么?

Vagrant调用正在Windows 10中运行。

0 个答案:

没有答案