test Docker on Mac OS X

支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

download docker for mac and install

download from
https://github.com/boot2docker/osx-installer/releases
, install the package, which will install a VirtualBox VM, Docker itself, and the Boot2Docker management tool.

start boot2docker

$ boot2docker help
$ boot2docker init
$ boot2docker info
$ boot2docker status
$ boot2docker start
Waiting for VM and Docker daemon to start…
……………………….
Started.

To connect the Docker client to the Docker daemon, please set: export DOCKER_HOST=tcp://192.168.59.103:2375

$ export DOCKER_HOST=tcp://192.168.59.103:2375
$ boot2docker ip
The VM’s Host only interface IP address is: 192.168.59.103

run docker hello world

$ docker run —help
$ docker run hello-world
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.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

For more examples and ideas, visit:
http://docs.docker.com/userguide/

run docker nginx

$ docker pull dockerfile/nginx (or $ docker run —rm -i -t -p 80:80 nginx)

$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
dockerfile/nginx latest 52cea49d86cf 3 weeks ago 436.7 MB
hello-world latest ef872312fe1b 6 weeks ago 910 B

$ docker run -d -p 8080:80 dockerfile/nginx

$ curl $(boot2docker ip):8080
Welcome to nginx!

$ docker info
Containers: 3
Images: 21
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Dirs: 27
Execution Driver: native-0.2
Kernel Version: 3.16.1-tinycore64
Operating System: Boot2Docker 1.2.0 (TCL 5.3); 3.16.1-config-file : e75396e - Fri Aug 22 06:45:30 UTC 2014 Debug mode (server): true
Debug mode (client): false
Fds: 11
Goroutines: 11
EventsListeners: 0
Init Path: /usr/local/bin/docker

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f208876adeb9 dockerfile/nginx:latest “nginx” 3 minutes ago Up 3 minutes 443/tcp, 0.0.0.0:8080->80/tcp angry_mayer

$ docker top f208
PID USER COMMAND
1532 root nginx: master process nginx
1542 33 nginx: worker process
1543 33 nginx: worker process
1544 33 nginx: worker process
1545 33 nginx: worker process

$ docker inspect —format ’ {{ .NetworkSettings.IPAddress }} ’ f208
172.17.0.14

$ docker logs a27633b9259b

$ docker stop f208876adeb9 (or $ docker attach a276)
f208876adeb9

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

update boot2docker

$ docker rmi $(docker images -a -q)

$ boot2docker stop

$ boot2docker download
Downloading boot2docker ISO image…
Latest release is v1.2.0
Success: downloaded https://github.com/boot2docker/boot2docker/releases/download/v1.2.0/boot2docker.iso
to /Users/abc/.boot2docker/boot2docker.iso

$ boot2docker start
Waiting for VM and Docker daemon to start…
……………………….
Started.

To connect the Docker client to the Docker daemon, please set:
export DOCKER_HOST=tcp://192.168.59.103:2375

$ echo $DOCKER_HOST

$ export DOCKER_HOST=tcp://192.168.59.103:2375

$ docker info

docker hub usage

$ docker search php

$ docker pull php

$ docker images

committing a container

$ docker run -i -t ubuntu /bin/bash

root@24808f660519:/# apt-get update

root@24808f660519:/# apt-get install openssh-server

root@24808f660519:/# mkdir /var/run/sshd

root@24808f660519:/# passwd

root@24808f660519:/# exit

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe2ba6471ff6 ubuntu:latest “/bin/bash” 41 hours ago Exited (0) 21 minutes ago thirsty_turing

$ docker attach fe2b root@24808f660519:/# exit

$ docker commit fe2b my/sshd

$ docker run -t -i my/sshd /bin/bash
root@4f99d56c048b:/# ls /usr/sbin/sshd
/usr/sbin/sshd

delete the boot2docker VM

$ docker kill 5654d3cf0d6b 5654d3cf0d6b

$ docker ps -a -notrunc

$ boot2docker stop

$ boot2docker delete boot2docker-vm

$ boot2docker init

Docker Links

$ docker run -d —name db training/postgres

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
66f2ec3a5aba training/postgres:latest “su postgres -c ‘/us 5 days ago Up 4 seconds 5432/tcp db

$ docker run —rm -ti —name web —link db:db training/webapp env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=369ef26bb91a
TERM=xterm
DBPORT=tcp://172.17.0.69:5432
DB
PORT5432TCP=tcp://172.17.0.69:5432
DBPORT5432TCPADDR=172.17.0.69
DBPORT5432TCPPORT=5432
DBPORT5432TCPPROTO=tcp
DBNAME=/web/db
DB
ENVPGVERSION=9.3
HOME=/

$ docker run —rm -ti —link db:db ubuntu /bin/bash
root@c6246191ef1e:/opt/webapp# cat /etc/hosts
172.17.0.71 c6246191ef1e
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.69 db
root@4f99d56c048b:/# ping db
PING db (172.17.0.69) 56(84) bytes of data.
64 bytes from db (172.17.0.69): icmp_seq=1 ttl=64 time=0.098 ms
… …

Creating and mounting a Data Volume Container

$ docker run —rm -ti —name web —volumes-from db —link db:db ubuntu /bin/bash

$ docker exec db touch /dbdata/test.txt

$ docker run —rm -ti —name web —volumes-from db —link db:db ubuntu /bin/bash
root@71825167ad4f:/# ls /dbdata/
test.txt

Backup, restore, or migrate data volumes

$ docker run —volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata

$ docker run -v /dbdata —name dbdata2 ubuntu /bin/bash

$ docker run —volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar

docker events

$ docker events &
[1] 13889

$ docker start 2b79
2014-11-22T10:05:20.000000000+09:00 2b7969a3aca9f1f4367f856c6d84f1d4fad95ce636eeb5948a819b714478fff2: (from ubuntu:14.04) start 2b79

$ docker stop 2b79
2014-11-22T10:05:32.000000000+09:00 2b7969a3aca9f1f4367f856c6d84f1d4fad95ce636eeb5948a819b714478fff2: (from ubuntu:14.04) die 2b79
2014-11-22T10:05:32.000000000+09:00 2b7969a3aca9f1f4367f856c6d84f1d4fad95ce636eeb5948a819b714478fff2: (from ubuntu:14.04) stop

$ docker events —since ‘2014-11-01’
2014-11-20T10:14:55.000000000+09:00 26a3bd791cd3040e9658d15411d81d85628c5e1f9cb49b0e09467a5ef6a16dc3: (from d8454392ade2) die
2014-11-20T10:16:07.000000000+09:00 bf709b179fb277767b78270786c8ea4630638259a9f53a2768155670fc2e129a: (from d8454392ade2) start
2014-11-20T10:17:40.000000000+09:00 bf709b179fb277767b78270786c8ea4630638259a9f53a2768155670fc2e129a: (from d8454392ade2) die
2014-11-20T10:17:41.000000000+09:00 9793173471d81141a197a416c04e6ba550e168582803a603b634797994f50b89: (from 59319fa4d82f) start



支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

links

https://docs.docker.com/installation/mac/

http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide

http://tech.lexues.co.jp/archives/1569

https://docs.docker.com/introduction/understanding-docker/

https://medium.com/dev-tricks/apache-and-php-on-docker-44faef716150

支 持 本 站: 捐贈伺服器等運維費用,需要您的支持!

發布時間: