我最近在DigitalOcean上创建了一个Droplet,以将我的本地开发文件部署在DigitalOcean上。我将运行docker-compose up
,并且可以使用远程IP地址访问该站点。但是我无法使用localhost
或127.0.0.1
访问它。我需要此本地访问权限,以便可以在没有互联网的情况下测试我的开发。
我已经使用docker-machine
驱动程序创建了digitalocean
,如下所示:docker-machine create --driver digitalocean --digitalocean-access-token $DOTOKEN machine-name
这是我的docker-compose.yml
文件:
data:
extends:
file: docker-compose-common.yml
service: data
db:
extends:
file: docker-compose-common.yml
service: db
ports:
# Publish the port so it's visible on the host, you can access the db directly
- "3306:3306"
environment:
# Environment variables to configure MySQL on startup.
# We don't care about commiting these creds to GitHub because they're only
# for our local development environment
- MYSQL_ROOT_PASSWORD=my-root-password-dev
- MYSQL_DATABASE=guestbook-dev
- MYSQL_USER=guestbook-admin
- MYSQL_PASSWORD=my-guestbook-admin-password-dev
volumes_from:
# Mount the volumes from the data container to store our MySQL files
- data
app:
extends:
file: docker-compose-common.yml
service: app
ports:
# Publish the port so it's visible on the host, you can access the app directly
- "8000:8000"
links:
# Link to the db service to store state
- db:db
volumes:
# Mount the app dir in the container as /src so our changes to the app code
# are also changed in the container
- ./app:/src
command: gunicorn --reload app:app --bind 0.0.0.0:8000
# Run Gunicorn to serve app requests and reload on change so we can see our
# changes to the app code
web:
extends:
file: docker-compose-common.yml
service: web
ports:
# Publish the port so it's visible on the host
- "80:80"
links:
# Link to the app to serve requests
- app:app
有什么办法可以通过本地主机访问我的 docker ?
PS:我使用Mac作为开发平台
最佳答案
不,这行不通。根据定义,在您的个人计算机上,“localhost
”是指您的个人计算机,而不是液滴。此外,由于Digital Ocean液滴不属于您的计算机,因此您无法不使用Internet来访问其液滴。它们是Digital Ocean服务器的一部分,您需要Internet才能访问它们。
关于docker - 使用本地主机访问DigitalOcean Docker Drop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52615236/