What is Docker? Docker is the next step on long IT containerization way. What does it mean? Years ago, you could run each application/process in particular container, that application couldn’t go outside the container which it was run.
Jul 24, 2018 Docker Toolbox installs multiple components on your Mac, each with their own purpose: Docker Client, Docker Machine, Docker Compose, Docker Kitematic and Virtual Box. The Docker Client and Machine are used to build and run containers, as well as create Docker hosts on your computer, cloud providers or data centers.
It was very safe but difficult to manage and not sharable. So you couldn’t easy share your container to other machine or to other developers to reuse for example by open source community. So, that solution was a little bit complicated and worked only on Linux.
Today we have Docker, which allows you to run containers on all operation systems. What is important, this tool is not only modern but also easy to manage and easy to share to others developers. Other ways to install it In this post, I want to show you how to install Docker by using brew which installation process I wrote last time. For me, it’s the easiest and safest way.
But there are a few other possibilities to install it on Mac OS. Docker.com – first method First what you have to do is to go to Docker website and just download and run the.dmg file. This is probably the easiest way, but unfortunately not the best. Using native install method you don’t have to install VirtualBox to run Linux, but sharing files between your Mac OS and systems in containers are really slowly. I can recommend that solution only if you want to test something or your project doesn’t use a framework with a lot of files.
Docker Toolbox – second method It’s an app provided by Docker Company for Mac OS and Windows. The special feature in this toolbox is the requirement for VirtualBox, which will be a supervisor to run Linux. So, Docker is available as another machine in Docker environment. This toolbox contains also docker-compose (more below) and Kinematic, which allow you to manage your container by using GUI than a command line. Install I guess you have installed brew if not just follow this page and do everything that I’ve described. If you are ready, open your terminal and type something like this: brew install docker docker-compose docker-machine xhyve docker-machine-driver-xhyve If you have done it that you’ve received notice that docker-machine-driver-xhyve has to run as root, so you have to execute that commands: sudo chown root:wheel $(brew -prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve sudo chmod u+s $(brew -prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve Both commands will ask you for a password. Don’t worry to type it in a command line.
If everything goes ok then you can create your first docker machine, just type this command: docker-machine create default -driver xhyve -xhyve-experimental-nfs-share This command, as you suppose, creates a docker machine, using the xhyve driver.xhyve-experimental-nfs-share – this flag allows you to share each file in your /Users/ folder between Mac OS and Linux run on Docker. Because you can have a lot docker machine, you can type this command in your terminal: eval $(docker-machine env default) It registers a few variables, which allow you to use default docker machine without typing “default” each time. Useful tools Probably, you’ve noticed that with docker you installed also docker-machine and docker-compose. These tools are not required but they are the strength of docker. Docker-machine This tool allows you to prepare a lot of docker machines on your Mac OS, so you can have a lot of containers on many Linux distributions. You can dump all available commands just by typing docker-machine -help but most likely you will use three of them: docker-machine start default docker-machine stop default docker-machine restart default I guess I don’t have to describe what exactly this commands do.
It’s so obvious. One thing you need to know, if something goes wrong, just try to restart your docker machine. Docker-compose The main goal of docker: you can write like this “one process = one container”, but each app requires a lot process it could be a PHP, HTTP server, some database etc. Of course, you can run containers for each process manually, which is not a big deal with 3 containers, but trust me it escalates very fast, so you need an easy tool to manage your container and to manage the dependencies because one container can require access to another container. For example, PHP app needs information from a database, but it doesn’t need access to HTTP server.
Of course, and HTTP server requires access to PHP. To work with docker-compose you need to create an YAML file called docker-composer.yml where you describe which container you want to create and how they are linked between each other. That file can look like this: version: '2' services: db: image: mysql:5.7 volumes: - dbdata:/var/lib/mysql restart: always environment: MYSQLROOTPASSWORD: wordpress MYSQLDATABASE: wordpress MYSQLUSER: wordpress MYSQLPASSWORD: wordpress wordpress: dependson: - db image: wordpress:latest ports: - '8000:80' restart: always environment: WORDPRESSDBHOST: db:3306 WORDPRESSDBPASSWORD: wordpress volumes: dbdata: As you can see, you are creating two containers, first, contains MySQL database and second one – a WordPress instance. This example is flattened, in normal case you should split WordPress instance to three another containers: PHP, HTTP server and one for WordPress files.
There is also created one volume, which contains files of MySQL database. This solution prevents loosing data when you turn off your Mac, or just reset docker-machine or this particular container. If you want to read something more about parameters available in docker-compose file, you can just go to docker documentation. Docker-compose, as well as other tools, provides a lot of commands available from a terminal, the number one is: docker-compose up -d -build -remove-orphans This command runs all containers defined in your docker-compose file. If it is needed – rebuild and remove old unused containers.
How to use Everything that you need is in the section above. You can manage of course each particular container directly from command line using command docker. But it’s just wasting a time.
Access by domain Probably you want to access to your container by your web browser using some domains. You need to know what is IP of your docker machine and you can check it using command line just typing this: docker-machine ip default You see IP and then use that IP in your /etc/hosts file. Potential problems Because you are trying to run Linux environment on Mac OS you can some across a lot strange problems if you want to use it in common work. Fortunately, you just need to follow some rules to enjoy work with docker. Sharing files If you installed a docker as described above you can share only files from your /Users/ folder. You can debug what is sharable directly on your docker machine, which can receive access directly from command line, like this: docker-machine ssh default Now, you are logged on your Linux and can browse to / and check is there /Users/ folder which contains files from your Mac OS.
If you don’t see your files, just try to reinstall Docker and xhyve. Speed of I/O process Because docker needs transfer files between your Mac OS and Linux using the NFS it’s always more slowly then operation directly on your disk. So, if you want to boost up your application you have to remember to share only needed files. If you are backend develop you don’t share frontend javascript libraries, just put in into inside container.
Don’t forget to ignore cache and logs files! Access via domain/IP Restarting Mac OS or docker-machine sometimes restarts also IP of the docker machine. If you can’t connect to your docker just check the current IP using this command: docker-machine ip default If it doesn’t work, you have to update domains in your /etc/hosts file.
Updated on November 20th, 2017 in Should You Install Docker With the Docker Toolbox or Docker for Mac / Windows? If you're running MacOS or Windows you have a few options for installing Docker. There's even a third way too, and we'll compare them here. Quick Jump: If you’re on MacOS or Windows you can install Docker with:. Docker for Mac / Windows. Docker Toolbox.
Running your own Virtual Machine and installing Docker yourself All 3 of those options have their own pros and cons and in this article we’re going to cover them. If you’re looking for a high level overview of what Docker for Mac / Windows and Docker Toolbox is, then check out this article on. OS and Hardware Requirements It’s helpful to know what you can install before we compare everything, so let’s do that: Docker for Mac Docker for Mac requires that you’re running Yosemite 10.10.3+ or newer but it’s worth mentioning that you should upgrade to 10.11+ because 10.10.x releases are considered “use at your own risk”. You CAN run VirtualBox alongside Docker for Mac as long you’re using a somewhat new version of VirtualBox. All of the 5.x releases are ok.
This is pretty useful because you might have some legacy apps running in Vagrant / VirtualBox to deal with (I know I do!). Docker for Windows Docker for Windows requires that you’re running Windows Pro, Enterprise, or Education edition. Sorry, Home edition isn’t available and that’s because Microsoft doesn’t currently allow Hyper-V to be installed on Home editions. Also, unlike Docker for Mac, you cannot run any version of VirtualBox, VMWare or any other Type 2 hypervisor along with Docker for Windows. That’s because Docker for Windows uses Hyper-V under the hood which is a Type 1 hypervisor. Docker Toolbox If you can’t run Docker for Mac or Docker for Windows then there’s the Docker Toolbox.
It has much less strict requirements. As long as you can run VirtualBox then you’re good to go (Docker Toolbox manages this for you). It works all the way back to MacOS 10.8 and Windows 7 (yep, even Home editions). Your own Virtual Machine Docker will happily run inside of VirtualBox, VMWare or any other Type 1 / 2 Hypervisor that’s running a major distribution of Linux. So, similarly to the Docker Toolbox, rolling your own VM has the same requirements.
Pros and Cons Now for the good stuff! Docker for Mac / Docker for Windows Pros. Offers the most “native” experience, you can easily use any terminal you you want since Docker is effectively running on localhost from MacOS / Windows’ POV. Docker is heavily developing and polishing this solution. Cons.
On Windows, if you have legacy apps that need a VM, you can’t reasonably do both. On Windows, volume mount performance is still quite poor, but it’ll improve in due time.
Update Nov 2017: Volume mount performance is very usable now on Windows! Docker Toolbox Pros. Offers an “out of the box” Docker experience if you have no other choice. May offer better volume mount performance under Windows (but this will change). Cons. You need to either use the Docker Quickstart Terminal, or configure your own terminal to connect to the Docker Daemon running a VM.
Not a native solution, so you’ll need to access your Docker Machine’s IP address if you’re developing web apps. Example: 192.168.99.100 instead of localhost. Suffers from typical VirtualBox edge case bugs and mount performance issues. Your own Virtual Machine I’m not going to bother listing a pros and cons here because I wouldn’t recommend doing this UNLESS you plan to go all in with a Virtual Machine set up. But more on that in a bit Which One Should I Use? If you’re interested in Docker, you’re a smart person and you probably came to the conclusion that using Docker for Mac or Docker for Windows is a good idea (if you can run it). My recommendation would be to try Docker for Mac / Windows first, and test it against your actual use cases.
The performance issues may or may not be a concern, especially since everyone’s needs and computer specs are different. On Windows and Like the Idea of Running Linux Too?
I want to mention a “roll your own VM” solution for Windows users because I feel like there’s an even better way to run Docker on Windows if you also like Linux. I no longer use what is described below It has been fully replaced with another Windows based set up that uses WSL and MobaXterm. It is super solid for full time development. It involves running VMWare in a special mode called “Unity mode”. This basically allows you to run Windows and Linux together seamlessly as 1 operating system. There’s no dual booting and Linux applications (even graphical apps) run in their own floating windows. Then you can install Docker natively on Linux inside of the VM.
The performance is excellent and the entire set up is free too. This is what I use personally and have been doing it for years. It gives you the best of both worlds. For example, I run high end audio / video apps on Windows while recording courses and screencasts that cover Linux content. It all works great (even for full time development). You can watch a video guide and see screenshots on how to do that in this post on.
Are you using the Docker Toolbox, Docker for Mac / Windows or your own VM?