Loading... # Docker For Mac Connect Container By Ip > Docker For Mac 一直存在一个问题,就是无法通过 ip 访问容器 。[Detail](https://docs.docker.com/docker-for-mac/networking/#there-is-no-docker0-bridge-on-macos) > 之前使用过以下方法 > > 1. 使用 docker-machine create vm ,虚拟机 static ip 来访问对应的容器。(容器 Port 映射 vm-machine Port) > 2. 使用 openvpn 连接容器 > 3. 以下使用新的方法 ## Docker-composer File Config ```yml version: '3' networks: laravel_share_network: ipam: config: - subnet: 192.168.240.0/24 services: nginx: image: nginx:stable-alpine container_name: nginx-beauty restart: always ports: - "9090:80" volumes: - ../beauty:/var/www/html/beauty - ./docker/nginx/beauty.conf:/etc/nginx/conf.d/default.conf depends_on: - php networks: laravel_share_network: ipv4_address: 192.168.240.5 php: image: biyongyao/php-fpm-dev:7.4 restart: always container_name: php-beauty volumes: - "./docker/php/config/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini" - "../beauty:/var/www/html/beauty" networks: laravel_share_network: ipv4_address: 192.168.240.2 ``` ## Using docker-connector ### Install by brew ```shell bash > brew install wenjunxiao/brew/docker-connector ``` ### Alter Config ```shell bash > vi /usr/local/etc/docker-connector.conf # route 192.168.240.0/24 expose ``` ### Start docker-connector ```shell # start service bash > sudo brew services start docker-connector # check whether start bash > brew services list ``` ### Start Docker to Create Virtual Network Card ```shell bash > docker run -it -d --restart always --net host --cap-add NET_ADMIN --name connector wenjunxiao/mac-docker-connector ``` ### Share With other Mac User 1. alter config ```shell # alter config bash > vi /usr/local/etc/docker-connector.conf ``` 2. text content ```text # text content route 192.168.240.0/24 expose token user1 192.168.240.100 token user2 192.168.240.110 ``` 3. install in other mac ```shell bash > brew install wenjunxiao/brew/docker-accessor bash > sudo docker-accessor -remote 192.168.240.100 -token user1 ``` Last modification:September 3, 2022 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 If you think my article is useful to you, please feel free to appreciate