如何使用 vagrant docker 提供程序查看 Nginx 默认页面?
How to see Nginx default page using vagrant docker provider?
我尝试 运行 我的 Nginx 服务器使用 vagrant docker 提供商,例如:
vagrant up
Vagrantfile
指令是:
# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
# Create and configure the Docker container(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network "private_network", ip: "192.168.66.66"
config.vm.provider "docker" do |docker|
docker.name = 'nginx-container'
docker.image = "nginx:latest"
docker.ports = ['80:80', '443:443']
end
end
如果我用 vagrant status
检查流浪者的状态,我得到:
Current machine states:
default running (docker)
The container is created and running. You can stop it using
`vagrant halt`, see logs with `vagrant docker-logs`, and
kill/destroy it with `vagrant destroy`.
当我尝试获取 http://192.168.66.66/
页面时,我得到 ERR_CONNECTION_TIMED_OUT
并且页面未加载。为什么我看不到 Nginx 默认网页?
vagrant up
期间在控制台中的日志是:
==> default: Docker host is required. One will be created if necessary...
default: Docker host VM is already ready.
==> default: Syncing folders to the host VM...
default: Installing rsync to the VM...
default: Rsyncing folder: /Users/victor/www/symfony/ => /var/lib/docker/docker_1430638235_29519
==> default: Warning: When using a remote Docker host, forwarded ports will NOT be
==> default: immediately available on your machine. They will still be forwarded on
==> default: the remote machine, however, so if you have a way to access the remote
==> default: machine, then you should be able to access those ports there. This is
==> default: not an error, it is only an informational message.
==> default: Creating the container...
default: Name: nginx-container
default: Image: nginx:latest
default: Volume: /var/lib/docker/docker_1430638235_29519:/vagrant
default: Port: 80:80
default: Port: 443:443
default:
default: Container created: b798ea3309612fb2
==> default: Starting container...
==> default: Provisioners will not be run since container doesn't support SSH.
这是几个月前的事了,但为了其他可能登陆这里的人,我还是会回答:
使用docker ps
查看你的图片标识符,应该是'b798ea3309612fb2'
然后做:
docker inspect b798ea3309612fb2 | grep IPAddress
因此您将确认 IP 地址。
既然你公开了端口,你应该在你的真实(无论你为 Vagrant 使用什么容器)IP 中看到它们。
确保没有防火墙阻止它们。
我尝试 运行 我的 Nginx 服务器使用 vagrant docker 提供商,例如:
vagrant up
Vagrantfile
指令是:
# Specify Vagrant version and Vagrant API version
Vagrant.require_version ">= 1.6.0"
VAGRANTFILE_API_VERSION = "2"
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
# Create and configure the Docker container(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network "private_network", ip: "192.168.66.66"
config.vm.provider "docker" do |docker|
docker.name = 'nginx-container'
docker.image = "nginx:latest"
docker.ports = ['80:80', '443:443']
end
end
如果我用 vagrant status
检查流浪者的状态,我得到:
Current machine states:
default running (docker)
The container is created and running. You can stop it using
`vagrant halt`, see logs with `vagrant docker-logs`, and
kill/destroy it with `vagrant destroy`.
当我尝试获取 http://192.168.66.66/
页面时,我得到 ERR_CONNECTION_TIMED_OUT
并且页面未加载。为什么我看不到 Nginx 默认网页?
vagrant up
期间在控制台中的日志是:
==> default: Docker host is required. One will be created if necessary...
default: Docker host VM is already ready.
==> default: Syncing folders to the host VM...
default: Installing rsync to the VM...
default: Rsyncing folder: /Users/victor/www/symfony/ => /var/lib/docker/docker_1430638235_29519
==> default: Warning: When using a remote Docker host, forwarded ports will NOT be
==> default: immediately available on your machine. They will still be forwarded on
==> default: the remote machine, however, so if you have a way to access the remote
==> default: machine, then you should be able to access those ports there. This is
==> default: not an error, it is only an informational message.
==> default: Creating the container...
default: Name: nginx-container
default: Image: nginx:latest
default: Volume: /var/lib/docker/docker_1430638235_29519:/vagrant
default: Port: 80:80
default: Port: 443:443
default:
default: Container created: b798ea3309612fb2
==> default: Starting container...
==> default: Provisioners will not be run since container doesn't support SSH.
这是几个月前的事了,但为了其他可能登陆这里的人,我还是会回答:
使用docker ps
查看你的图片标识符,应该是'b798ea3309612fb2'
然后做:
docker inspect b798ea3309612fb2 | grep IPAddress
因此您将确认 IP 地址。
既然你公开了端口,你应该在你的真实(无论你为 Vagrant 使用什么容器)IP 中看到它们。 确保没有防火墙阻止它们。