Docker不在主机上为Mac上的容器打开端口

时间:2020-06-17 16:18:21

标签: docker docker-compose

我有一个docker-compose文件来运行两个不同版本的mysql:

version: "3.8"
services:

  mysql_5.6:
    image: mysql:5.6
    restart: always
    ports:
      - "3307:3306"

  mysql_latest:
    image: mysql:latest
    restart: always
    ports:
      - "3308:3306"

我从docker-compose -f docker/docker-compose.yml up -d开始。运行docker ps我得到:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                          PORTS               NAMES
9649cd3df592        mysql:latest        "docker-entrypoint.s…"   About a minute ago   Restarting (1) 28 seconds ago                       docker_mysql_latest_1
339b5a7f2262        mysql:5.6           "docker-entrypoint.s…"   About a minute ago   Restarting (1) 28 seconds ago                       docker_mysql_5.6_1

您可以看到“端口”部分为空。用telnet或MySqlWorkbench连接使我预期的连接被拒绝。我在macOS Catalina上运行Docker Desktop 2.3.0.3(45519)。我已添加Docke,以允许在“防火墙”设置中打开连接。

如何使Docker在Mac上打开端口?

1 个答案:

答案 0 :(得分:0)

似乎问题出在我没有指定root密码。现在可以使用:

version: "3.7"
services:

  mysql_5.6:
    image: mysql:5.6.44
    restart: always
    ports:
      - "3307:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ""
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

  mysql_latest:
    image: mysql:latest
    restart: always
    ports:
      - "3308:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ""
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"