What's the right way to set up a development environment on OS X with Docker?

后端 未结 10 1354
野性不改
野性不改 2020-12-04 05:39

Intro

I can\'t figure out a good way to set up a development environment on OS X using Docker and Boot2Docker. The problem I\'m hitting is how to manage the source

相关标签:
10条回答
  • 2020-12-04 05:58

    Docker for Mac and Windows shall be the definitive way of developing with Docker on OS X (and Windows). A Docker product, the software is an “integrated, easy-to-deploy environment for building, assembling, and shipping applications from Mac or Windows.” It purports to be able to solve the issues presented by the OP. From its March 24, 2016 announcement:

    • Faster and more reliable: no more VirtualBox! The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X or on a Hyper-V VM on Windows, and that VM is managed by the Docker application. You don’t need docker-machine to run Docker for Mac and Windows.
    • Tools integration: Docker for Mac is a Mac application and Docker for Windows is a Windows application, including a native user interface and auto-update capability. The Docker tool set comes bundled with it: Docker command line, Docker Compose, and Docker Notary command line.
    • Volume mounting for your code and data: volume data access works correctly, including file change notifications (on Mac inotify now works seamlessly inside containers for volume mounted directories). This enables edit/test cycles for “in container” development.
    • Easy access to running containers on the local host network: Docker for Mac and Windows include a DNS server for containers, and are integrated with the Mac OS X and Windows networking system. On a Mac, Docker can be used even when connected to a very restrictive corporate VPN.
    • Docker for Mac was architected from scratch to be able to fit the OS X sandbox security model and we are working closely with Apple to achieve this.
    0 讨论(0)
  • 2020-12-04 06:02

    I've been developing in a OS X (mid 2011 Macbook Air) + Boot2Docker + Docker-compose environment for a few weeks now. Haven't run into major performance issues but I avoid running any sort of build when developing (why not use something like jekyll serve --skip-initial-build?). Here's an example docker-compose.yml file I'm using:

    docker-compose.yml:

    test:
      build: .
      volumes:
        - ./client:/src/client
        - ./server:/src/server
        - ./test:/src/test
      command: nodemon --exec jasmine-node -- test/ --verbose --autotest --captureExceptions --color
      environment:
        - DEBUG=*
    

    Dockerfile:

    FROM node:0.12
    
    RUN mkdir -p /src
    WORKDIR /src
    
    ENV PATH=/src/node_modules/.bin:$PATH
    
    # We add package.json first so that we the
    # image build can use the cache as long as the
    # contents of package.json hasn't changed.
    
    COPY package.json /src/
    RUN npm install --unsafe-perm
    
    COPY . /src
    
    CMD [ "npm", "start" ]
    EXPOSE 3000
    

    I sometimes use NFS (http://syskall.com/using-boot2docker-using-nfs-instead-of-vboxsf/) but haven't noticed a big performance difference when doing so.

    For me, the convenience of a simple docker-compose up test to get my environment running has been worth the cost in performance (I routinely work on multiple projects with different stacks).

    PS: nodemon is one of the few file watchers which work with vboxsf (see https://github.com/remy/nodemon/issues/419).

    0 讨论(0)
  • 2020-12-04 06:08

    I'm also using Vagrant with parallels and boot2docker (https://github.com/Parallels/boot2docker-vagrant-box). Development was never easier for me. Works really well with docker-compose and large setups. I don't really feel a delay or massive resource consumption.

    This is what my Vagrantfile looks like:

    Vagrant.configure(2) do |config|
    
      config.vm.network "private_network", ip: "192.168.33.10"
      config.vm.box = "parallels/boot2docker"
    
      config.vm.synced_folder "/Users", "/Users", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync"
    
    end
    
    0 讨论(0)
  • 2020-12-04 06:09

    Disclaimer: I might be biased, since I am the author of docker-sync.

    I probably tried all the solutions named here, including some more (see the compersion https://github.com/EugenMayer/docker-sync/wiki/Alternatives-to-docker-sync), but they basically either failed on the side of performance (most of them) or on the docker-machine (or none) used / enforced.

    http://docker-sync.io has been built to merge all the solutions and provide the best strategies (implementing several, you can choose).

    It can be used with rsync (1 way sync) including permission fixes for users, and with unison (2 way sync). It does neither force you into docker-machine or a specific hypervisor, nor requires you to have docker for Mac. It works with all of them.

    The performance EugenMayer/docker-sync/wiki/4.-Performance is not influenced, it's like you have no shares at all.

    docker-sync and its change-watchers are optimized and do work with projects with 12k files without issues.

    Give it a try, if you like, I would love to hear feedback!

    0 讨论(0)
提交回复
热议问题