使用localhost访问DigitalOcean Docker droplet

s8vozzvw  于 2023-10-16  发布在  Docker
关注(0)|答案(2)|浏览(116)

我最近在DigitalOcean上创建了一个droplet,以便在DigitalOcean上部署我的本地开发文件。我会运行docker-compose up,我可以使用远程IP地址访问该网站。但是我不能使用localhost127.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作为我的开发平台。

insrf1ej

insrf1ej1#

不,这样不行。在你的个人电脑上,“localhost”,根据定义,指的是你的个人电脑,而不是液滴。此外,如果不使用互联网,你就无法访问你的水滴,因为数字海洋水滴不是你电脑的一部分;它们是数字海洋服务器的一部分,你需要互联网才能访问它们。

unftdfkk

unftdfkk2#

您必须为本地机器安装Docker作为开发和测试空间docker-compose.yml,命令如下:
docker-machine create -d virtualbox default
在配置合适并准备好部署之后,您可以在digitalocean上创建一个docker-machine

相关问题