The docker-machine command offers very cool features in order to operate with Docker images/container. The first basic features I would like to present in this tutorial.
If you want to test dockerized applications, you need to export/import Docker images or Docker containers. Therefor Docker offers various options and commands. In this tutorial i show some possibilities without Docker Hub or Docker registry.
This time again a tutorial with various instructions. It is a REST API services for development and testing purposes and some simple Docker instructions.
# create new boot2docker vm
$ docker-machine create -d virtualbox apivm
# list created vm(s)
$ docker-machine ls
# list informations (optional)
$ docker-machine inspect apimock
# ssh into boot2docker vm
$ docker-machine ssh apivm
Create Dockerfile (inside VM)
# create new Dockerfile
$ vi Dockerfile
FROM ubuntu
# install python packages
RUN apt-get update && apt-get -y install python python-dev python-pip
# install python libraries
RUN pip install mock-server tornado==4.2
# create directory
RUN mkdir -p api
EXPOSE 8888
CMD ["mock-server","--address=0.0.0.0","--dir=api"]
Create Docker image and container (inside VM)
# create Docker image
$ docker build -t api_image .
# list Docker image(s)
$ docker images
# create and start new container from Docker image
$ docker run --name api_container -d -p 8888:8888 api_image
# list Docker container(s)
$ docker ps -a
Run application in browser
Now open a browser and call URL like: http://<192.168.99.100>:8888/__manage. You can now begin to create and use REST API resources.
The configuration of the Boot2Docker VM, still has a few drawbacks. You can not permanently store, the root password must be set again, SSH keys always changing … and so on. In this part we will change that.
# change to Default Machine Folder
$ cd VirtualBox\ VMs/
# create storage medium for VM
$ VBoxManage createhd --filename ./Boot2DockerVM/disk.vdi --size 8000
# attache storage medium to VM
$ VBoxManage storageattach "Boot2DockerVM" --storagectl "IDE" --port 1 --device 0 --type hdd --medium ./Boot2DockerVM/disk.vdi
# reconfigure boot settings of VM
$ VBoxManage modifyvm "Boot2DockerVM" --boot1 dvd --boot2 disk --boot3 none --boot4 none
# start vm
$ VBoxManage startvm Boot2DockerVM --type gui
Prepare disk
# format disk
$ mkfs.ext4 /dev/sda
# mark filesystem
$ tune2fs -L boot2docker-data /dev/sda
# restart VM
$ reboot
Set permanent root password
# check disk
$ df -h
# change directory
$ cd /mnt/sda/var/lib/boot2docker/
# create bootlocal.sh
$ vi bootlocal.sh
# content of bootlocal.sh (please use your own password)
echo "root:test123" | chpasswd
# change access rights
$ chmod +x bootlocal.sh
From this point, you can connect via SSH as root user.
The VirtualBox online-manual writes “Forwarding host ports < 1024 impossible…”. This tutorial shows that it is still possible. I know that there are several reasons not to do so, but there are also reasons where it is necessary.
Conditions
VirtualBox with VM configured (not running)
You know the root password
Example for Ubuntu
# become root
$ sudo su -
# start VirtualBox Manager
$ virtualbox
Now you probably need to import the VM. Attention! The acces rights will be changed!
Port Forwarding
Configure or just check the port forwarding. To do so, you can use the graphical port forwarding editor or even the command line (VBoxManage).