Before running this tutorial, you need to install Docker on your computer (https://docs.docker.com/installation/).
To run docker under Mac OSX, you must first run the program boot2docker.
boot2docker start
Important: when starting, boot2docker will display an message indicating the local IP of your docker host.
2014/08/12 09:43:36 Waiting for VM to be started... ....... 2014/08/12 09:43:58 Started. 2014/08/12 09:43:58 Trying to get IP one more time 2014/08/12 09:43:58 To connect the Docker client to the Docker daemon, please set: 2014/08/12 09:43:58 export DOCKER_HOST=tcp://192.168.59.103:2375
Before running docker, you must export the corresponding environment variable. Type the following command in the terminal (replace [...] by the actual address reported by boot2docker).
export DOCKER_HOST=tcp://192.168.59.103:2375
Tip:You can always obtain the IP address of your boot2docker host with the following command:
boot2docker ip
Connect to the shared folder using Finder (OS X).
Connect to cifs://192.168.59.103/data
Once mounted, will appear as /Volumes/data
# Make a volume container (only need to do this once) docker run -v /data --name my-data busybox true # Share it using Samba (Windows file sharing) docker run --rm -v /usr/local/bin/docker:/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba my-data # then find out the IP address of your Boot2Docker host boot2docker ip ## Should return something like this: 192.168.59.103
More information about boot2docker is available on the Docker Web site https://docs.docker.com/installation/mac/.
Check that docker is installed on your machine
docker version
Get the list of docker commands
docker
Docker's "Hello world" test
Test the following command to check that docker is
working fine.
docker run hello-world
Running a command in an Ubuntu 12.04 shell
The following command will download (if required) an
image of Ubuntu 12.04, and run a simple command in it.
docker run ubuntu:12.04 echo "Hello world"
The first time you run ubuntu:12.04, docker will download the image (this can take a few minutes, depending on the speed of your Internet connection). The next calls tu ubuntu:12.04 will immediately launch the local image, and you will be able to instantly execute any command under Ubuntu 12.04, as you will notice by typing the command again.
docker run ubuntu:12.04 echo "Hello world again"
Getting the list of docker images
To obtain a list of all the docker images running on
your machine, type
docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 c4ff7513909d 34 hours ago 225.4 MB ubuntu 12.04 822a01ae9a15 34 hours ago 108.1 MB hello-world latest 565a9d68a73f 4 weeks ago 922 B
Removing docker images
Docker images and containers occupy a relatively
important space on your hard drive, so after having played
around with docker, you will probably like to remove
images you don't intend to use anymore.
However, docker will not allow you to remove an image as long as there are still some containers depending on it (for the difference betwen image and container, see here). We will thus proceed in the following order:
docker ps -as
docker ps -as | grep hello-world
docker rm $(docker ps -as | grep hello | awk '{print $1}')
docker images | grep hello-world
docker images | grep hello-world | awk '{print $3}' | xargs docker rmi
Exercise: apply the same protocol to delete the ubuntu:14.04 image (assuming you did run it, and you don't need it anymore).
Docker allows you to run alternative distributions of Linux (for example Ubuntu, Centos, ...), or alternative versions of a given distribution (for example Ubuntu 14.04 and 12.04). This is particularly convenient for checking software portability.
In the previous example, we choose Ubuntu 12.04 because it occupies less space (108Mb) than the current Ubuntu release (14.04 in August 2014). If you dispose of a fast connection and are not too limited in hard drive space, you can re-run the command above replacing ubuntu:12.04 by ubuntu:14.04. This will require to tranfer 225.4Mb from the docker image repository, and to occupy the same space on your hard drive.