install boot2docker
-
download
Boot2Docker-x.x.x.pkg
-
install boot2docker by double-clicking the package
-
the installer places
Boot2Docker
in yourApplication
folder -
the installer places
docker
andboot2docker
in/usr/local/bin
-
-
start the boot2docker application
-
to run a docker container, you first start the
boot2docker
vm -
then issue
docker
commands tocreate, load and manage
containers -
you can launch
boot2docker
from application folder or form command line
-
init and run boot2docker
-
from the application folder
-
opens a terminal window
-
creates a ~/.boot2docker dir
-
creates a virtualbox iso and certs
-
start a virtualbox vm running the docker daemon
-
-
from command line
-
create a new
boot2docker
vm# this creates a new vm # need to run only once $ boot2docker init
-
start the
boot2docker
vm$ boot2docker start # or $ boot2docker up
-
display the environment variables for the docker client
$ boot2docker shellinit Writing /Users/hqlgree2/.boot2docker/certs/boot2docker-vm/ca.pem Writing /Users/hqlgree2/.boot2docker/certs/boot2docker-vm/cert.pem Writing /Users/hqlgree2/.boot2docker/certs/boot2docker-vm/key.pem export DOCKER_CERT_PATH=/Users/hqlgree2/.boot2docker/certs/boot2docker-vm export DOCKER_TLS_VERIFY=1 export DOCKER_HOST=tcp://192.168.59.103:2376
-
to set the environment variables in your shell do the following
$ eval "$(boot2docker shellinit)" # you can also set them manually # by using the `export` command `boot2docker` returns
-
run the
hello-world
container to verify your setup$ docker run hello-world
-
stop the
boot2docker
vm$ boot2docker stop # or $ boot2docker down
-
-
upgrade boot2docker
-
stop the
boot2docker
application -
run the upgrade command
$ boot2docker upgrade
-
-
access container ports
-
start an nginx container on the DOCKER_HOST
# `docker run` starts a container runs it and then exits # `-d` flag keeps the container running in the background # `-P` flag publishes exposed ports from container to your local host $ docker run -d -P --name web nginx
-
display your running container with
docker ps
command# at this point you can see # `nginx` is running as a daemon $ docker ps
-
view just the container’s ports
# `web` container's port `80` # is mapped to port `49157` on your docker host $ docker port web 443/tcp -> 0.0.0.0:49156 80/tcp -> 0.0.0.0:49157
-
enter
http://localhost:49157
address (localhost
is0.0.0.0
) in your browser# this webpage is not available # this didn't work # `DOCKER_HOST` address is not the localhost address `0.0.0.0` # but instead the address of the `boot2docker` vm # get the address of the `boot2docker` vm $ boot2docker ip 192.168.59.103 # enter the `http://192.168.59.103:49157` welcome to nginx! ...
-
to stop and then remove your running
nginx
container$ docker stop web $ docker rm web
-
-
mount a volume on the container
when you start `boot2docker` it automatically shares your `/Users` directory with the vm
-
create a website in
$HOME
$ cd $ mkdir site $ cd site # create a new `index.html` file $ echo "my new site" > index.html
-
start a new
nginx
container and replace thehtml
folder with yoursite
directory$ docker run -d -P -v $HOME/site:/usr/share/nginx/html --name mysite nginx # get the `mysite` container's port $ docker port mysite 80/tcp -> 0.0.0.0:49166 443/tcp -> 0.0.0.0:49165
-
visit this site in a browser
$ open http://192.168.59.103:49166
-
try adding a page to your
$HOME/site
in real time$ echo "this is cool" > cool.html # open the new page in the browser $ open http://192.168.59.103:49166/cool.html
-
stop and then remove your running
mysite
container$ docker stop mysite $ docker rm mysite
-
demo
-
$ docker run hello-world
$ docker run hello-world Unable to find image 'hello-world:latest' locally 511136ea3c5a: Pull complete 31cbccb51277: Pull complete e45a5af57b00: Pull complete hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Status: Downloaded newer image for hello-world:latest Hello from Docker. This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Assuming it was not already locally available.) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
-
$ docker run -it ubuntu bash
$ docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from ubuntu 706766fe1019: Pull complete a62a42e77c9c: Pull complete 2c014f14d3d9: Pull complete b7cf8f0d9e82: Already exists ubuntu:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:80d996c3693d792505039a3612cf9221ae9704317ea11fda75c86ede672ee1b3 Status: Downloaded newer image for ubuntu:latest