# [Docker](https://www.docker.com/)

Existing Docker images are available at [https://registry.hub.docker.com/](https://registry.hub.docker.com/). If you use docker you should create an account so that you can upload and store your own images.

## Docker Basics

### A note about developing with Docker on Mac OS X

Docker runs on Linux. You can run it on Mac using boot2docker, but it fires up VM to run the linux image in VirtualBox. Managing the size of the VirtualBox VM is a pain and Docker often runs up against the size limitation. I've found it's better to run a Linux VM in VMWare Fusion, and running Docker in that image.

### Docker commands

#### Start a Docker Container
```bash
sudo docker start <container_id> # Start
sudo docker stop <container_id>  # Stop

```

#### To start docker interactively:

```bash
sudo docker run -i -t ubuntu /bin/bash

# ubuntu is the name of the the docker container. 
# You could also use the container id (hex) instead
```

- Exiting the Docker's bash shell immediately shuts down the interactive session
- You can't run sudo commands in this Docker bash shell, for example you can run mount.

#### To start docker interactively with sudo privelages

```bash
sudo docker --privelaged -i -t ubuntu /bin/bash

# now sudo and mounts work
mount -t tmpfs stuff /mnt
```

#### Show Docker processes

```bash
sudo docker ps    # show running docker containers
sudo docker ps -a #  ... also shows process history
```

#### Run Docker container continuously
```bash
sudo docker start <container_id>
sudo docker ps                   # find id of process
sudo docker inspect --format "{{ .State.Pid }}" <container_id> # Find local pid (process id)

# This command will enter a running docker container w/ a terminal session
sudo nsenter --target <pid> --mount --uts --ipc --net --pid
```

__NOTE:__ [https://github.com/jpetazzo/nsenter](https://github.com/jpetazzo/nsenter) for installing nsenter on Ubuntu. It also installs `docker-enter` which is handy for entering running containers:

```bash
sudo docker-enter <container_id>
```


## Working with Docker Images

```bash
sudo docker images               # list image on my system and their ids
sudo docker pull <image_name>    # pulls and preloads image
sudo docker search <search_term> # Search images with names like search_term

# A refined search example
sudo docker search apache | grep ubuntu
```

You can use `apt-get` inside a container to install software in it. Then, to commit it locally:

```bash
sudo docker commit -a="Brian Schlining" <container_id> <new_local_image_name>
```


## Videos

- [Run Any App on Mesos on Any Infrastructure Using Docker](https://www.youtube.com/watch?v=u5jd9YT9EsY)

