Code Monkey home page Code Monkey logo

docker-macos-network's Introduction

Docker-MacOs-Network

Solving the Problem that Docker Desktop for Mac can’t route traffic to containers and You can access the containers by IP right away away in Docker for Mac Platform!

Problem

  • Install a Docker for Mac
  • Run a Hadoop image in Docker
  • View Hadoop HDFS WebUI by Using Hadoop containers IP
        docker inspect bbbbb | grep "IPAddress"

  • Visit http://172.17.0.2:50070/  Found out I can't access HDFS WebUI
  • Try to ping container ip from mac terminal, it's failed too!
  • Then I checked the official docker documentation and found out the problem Docker Documentation
  • If you want to connect a container from the Mac, you need to use Port Mapping like below
        docker run -d –it -p 50070 -p 8088 --name bbbbb sequenceiq/hadoop-docker:2.7.1
  • But I found some other problems, such as can't open log file, can't download Hadoop output result file. from WebUI directly! You have to reach those file by using terminal command, Troublesome!

Here is the solution!

  • Using Docker for Mac an experimental function: Socket Proxy

  1. Open Mac terminal and install jq

        brew install jq

  2. Change Docker configuration

        cd ~/Library/Group\ Containers/group.com.docker/
        mv settings.json settings.json.backup
        cat settings.json.backup | jq '.["socksProxyPort"]=8888' > settings.json

  3. Restart Docker for Mac

  4. Go System Preference -> Network -> Advanced ->

   Proxies -> Select Automatic Proxy Configuration ->

   Type http://localhost/socket.pac into the URL

  5. Start Mac local Apache service

        sudo apachectl start

  6. Check Apache service status, Visit http://localhost,

   it's started successfully if the browser shows "It works!"

  7. Create Pac file, File name : socket.pac, content below

        function FindProxyForURL(url, host) {
        if (isInNet(host, '172.17.0.0', '255.255.0.0')) {
        return 'SOCKS5 127.0.0.1:8888'
        }
        if (isInNet(host, '172.22.0.0', '255.255.0.0')) {
        return 'SOCKS5 127.0.0.1:8888'
        }
        return 'DIRECT'
}

  8. Put socket.pac file in directory /Library/WebServer/Documents

   and Visit http://localhost/socket.pac, if the browser shows:

  9. Check the containers hosts,get hosts 172.17.0.2 aaaaa

        cat /etc/hosts

  10. Modify the MacOs hosts File(Add 172.17.0.2 aaaaa to hosts file)

        vim /etc/hosts   

  11. The Socket Proxy configuration is finished!

  12. Run Hadoop Docker image

  13. Visiting HDFS WebUI and Resource Manager WebUI have two ways

  • By Port Mapping!
        http://localhost:32769
        http://localhost:32768
  • By containers IP right away!
        http://172.17.0.2:8088
        http://172.17.0.2:50070

The benefits of using containers IP to access WebUI

  • It won't occupy your Mac local Port
  • All WebUI support invoke each other, such as
  • ResourceManager Web UI: 8088
  • NodeManager Web UI: 8042
  • NameNode Web UI: 50070
  • DataNode Web UI: 50075
  • Secondary NameNode Web UI: 50090
  • JobTracker Web UI: 50030
  • TaskTracker Web UI: 50060
  • Looking at current status of HDFS, explore file system
  • Exploring file system, download HDFS file directly
  • Checking status and log file

Referenced Documentation

[D1] https://docs.docker.com/docker-for-mac/networking/
[D2] https://windmt.com/2019/08/30/docker-for-mac-network/
[D3] https://www.jianshu.com/p/d006a34a343f

docker-macos-network's People

Contributors

carl-xiao128 avatar

Stargazers

Christian Fochler avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.