2

I'm new to Docker...

From my understanding, Docker is only compatible with Linux, is it possible to run docker for development purposes on a Mac?

I installed virtualbox using homebrew and have tried to create a virtualbox instance. I installed docker, but am having trouble getting my mac to communicate with the vm docker instance. My end goal is to get a locally debuggable instance of tomcat running on the docker container.

Any help or tips would be helpful.

hhs_oz34
  • 41
  • 1
  • 6
  • Possible duplicate of [Install Docker Toolbox on a Mac via command line](https://stackoverflow.com/questions/32744780/install-docker-toolbox-on-a-mac-via-command-line) – Paul Sweatte Jun 30 '17 at 05:07

3 Answers3

2

Information:

Because Docker only runs on Linux you will need to install some kind of virtual instance on your local machine. An easy and popular way to do that is to install Boot2docker and VirtualBox. VirtualBox is a dependency of Boot2docker. You can download, setup and install the latest versions from their websites or if you are using Homebrew, as you mentioned, you can quickly get the working binaries both in one step.

After installing boot2docker, you're ready to use Boot2docker to create a Tomcat Container. You can find a pre-configured tomcat image by searching Docker's community repository, docker hub registry.

Notes:

  • Each time you execute the docker run command a new container is created.
  • The VM running Docker requires a ssh private/public encryption key handshake to connect to. If you follow my steps below, one will be generated for you.

Steps to Setup Tomcat using the tomcat image:

  1. Open Terminal and run this command: brew install boot2docker
  2. Create a new Boot2Docker VM instance using the init command: boot2docker init
  3. Run this command in Terminal to forward local ports to the vm:
for i in {10000..10999}; do VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i”; VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";done
  1. Start the boot2docker daemon: boot2docker start or boot2docker up
  2. After starting docker, copy the exports that are displayed from the previous command to your clipboard
  3. Edit your bash profile file ~/.bash_profile (or if you are using zsh, edit the resource configuration file ~/.zshrc) with a text editor (I prefer using Sublime text): subl .zshrc *note: this will permanently save the docker env variables.
  4. Paste the exports into that file and save
  5. Execute the source command on the file: source .zshrc
  6. Pull the latest tomcat image to create a container and start tomcat: docker run -it --rm -p 10080:8080 tomcat:8.0 *note: this will forward your local 10080 port to the vm's 8080 port.
  7. Go to http://localhost:10080, you should see the tomcat start page!

Useful Docker commands:

  • $ boot2docker status
  • $ docker version
  • $ docker ps #shows running containers
  • $ docker ps -a # shows all containers
  • $ docker exec -it NAME /bin/bash #to start a bash session on the container. -i = interactive, -t = tty

External Resources:

cosbor11
  • 14,709
  • 10
  • 54
  • 69
  • `+1`: Great explanation. One question though. Step 10, shouldn't it be the ip specified on `DOCKER_HOST` export and not localhost? – jaypal singh Sep 15 '15 at 01:28
  • Either one will work, you could go to the up address of the virtual machine as well – cosbor11 Sep 15 '15 at 01:35
  • Hmm .. I tried with `localhost`. Didn't seem to work, though I was able to see tomcat UI with `DOCKER_HOST` ip. – jaypal singh Sep 15 '15 at 02:22
  • 1
    Did you do step 3? Where you forward local port requests to the docker vm? Also double check which port you are trying to access. In my example it's not 1080, or 8080, it's 10080 and matches the port range from step 3 – cosbor11 Sep 15 '15 at 03:01
  • Aah my bad. Yes I missed that part! Thanks for the prompt responses! Appreciate it! `:)` – jaypal singh Sep 15 '15 at 04:08
1

Most people use boot2docker to run on Macs. You may also want to take a look at Kitematic, which gives you a GUI to play with.

Finally, the future is probably to use docker machine, which can provision a VM for you.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
0

Docker requires Linux Kernel features, hence it cannot be run natively on OSX.

See instead Boot2Docker. This link gives you instructions on how to get going.

mattias
  • 2,079
  • 3
  • 20
  • 27