为了在DigitalOcean上部署我的本地开发文件,我最近在DigitalOcean上创建了一个droplet。我将运行docker-compose up,并且我可以使用远程IP地址访问该站点。但我不能使用localhost或127.0.0.1访问它。我需要这个本地访问,所以我可以测试我的发展没有互联网。
我使用digitalocean驱动程序创建了docker-machine,如下所示:
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有没有办法用localhost访问我的docker?
PS:我正在使用Mac作为我的开发平台
发布于 2018-10-03 03:44:36
不,这行不通的。在您的个人计算机上,根据定义,"localhost“指的是您的个人计算机,而不是水滴。此外,如果不使用互联网,你就无法访问你的水滴,因为数字海洋水滴不是你计算机的一部分;它们是数字海洋服务器的一部分,你需要互联网来访问它们。
https://stackoverflow.com/questions/52615236
复制相似问题