Mac OS + Ubuntu VirtualBox + Ubuntu Docker Image

This article is about how to install Docker on your Ubuntu virtual machine running on Mac OS or Windows properly so that you can use Ubuntu docker images. I decided to write it after spending 4 hours searching for all necessary bits and pieces.

First of all you have to create Ubuntu virtual machine and install Ubuntu on it.

 Installing Docker

1. In the installed Ubuntu open a console window (Ctrl+Alt+T)

2. Install curl

$ sudo apt-get update
$ sudo apt-get install curl

3. Get the latest docker

$ curl -sSL | sh

4. Add your user to the “docker” group

$ sudo usermod -aG docker john

5. Log out and log in again in order to apply the changes from previous step and open a terminal window.

6. Verify your installation

$ docker run hello-world

Fixing issues with DNS

Now we have to fix some issues with the docker installation otherwise none of the docker images will get access to DNS.

1. Check your local DNS server on your OS X computer. Open a Terminal window and run the following

$ scutil --dns | grep nameserver\[[0-9]*\]

On my computer the result would be:

Other steps should be performed in the Ubuntu Terminal window
2. Open the /etc/default/docker file for editing.

$ sudo nano /etc/default/docker

3. Uncomment DOCKER_OPTS and replace the default dns addresses with your local DNS.


4. Exit the editor and save /etc/default/docker
5. Open the /lib/systemd/system/docker.service for editing

$ sudo nano /lib/systemd/system/docker.service

6. To the Service section add the following line:


7. Add $DOCKER_OPTS to ExecStart,

ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS

8. Exit the editor and save /lib/systemd/system/docker.service
9. Flush the changes you’ve made

$  sudo systemctl daemon-reload

10. Restart docker service

$ sudo systemctl restart docker

Running Ubuntu Docker image

Finally you can run Ubuntu image and check that network is available for it.
1. Run Ubuntu docker image

$ docker run -i -t ubuntu:14.04 bash

2. In the new (Ubuntu docker image) console check if the DNS server address was correctly propagated to resolv.conf

$ cat /etc/resolv.conf

3. Try to ping Everything should work.

$ ping

You may also like...