13.
One Server Multi Projects
Server
App 1
PHP
MySQL
etc…
App 2
PHP
MySQL
etc…
App n
PHP, DB,
etc…
……
14.
One Server Multi Projects
Server
App 1
PHP 5.3.2,
MySQL 5.0.2,
etc…
App 2
PHP 5.4,
MySQL 5.0.15,
etc…
App n
PHP 5.4,
MariaDB,
etc…
……
BUT DIFFERENT
REQUIRMENT
26.
How docker can help us?
Built specify environment for target project.
27.
How docker can help us?
Built specify environment for target project.!
Isolate every project space.
28.
How docker can help us?
Built specify environment for target project.!
Isolate every project space.!
Package it and be portable.
29.
How docker can help us?
Built specify environment for target project.!
Isolate every project space.!
Package it and be portable.!
Deploy lightweight and fast.
79.
Version
$ docker version
Client version: 1.3.0
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): c78088f
OS/Arch (client): linux/amd64
Server version: 1.3.0
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): c78088f
86.
List images
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.10 2185fd50e2ca 28 hours ago 237.2 MB
ubuntu utopic 2185fd50e2ca 28 hours ago 237.2 MB
ubuntu 14.04.1 9cbaf023786c 28 hours ago 192.8 MB
ubuntu 14.04 9cbaf023786c 28 hours ago 192.8 MB
ubuntu trusty 9cbaf023786c 28 hours ago 192.8 MB
ubuntu latest 9cbaf023786c 28 hours ago 192.8 MB
ubuntu precise a9561eb1b190 28 hours ago 120.2 MB
ubuntu 12.04.5 a9561eb1b190 28 hours ago 120.2 MB
ubuntu 12.04 a9561eb1b190 28 hours ago 120.2 MB
ubuntu 12.10 c5881f11ded9 3 months ago 172.2 MB
ubuntu quantal c5881f11ded9 3 months ago 172.2 MB
ubuntu 13.04 463ff6be4238 3 months ago 169.4 MB
ubuntu raring 463ff6be4238 3 months ago 169.4 MB
ubuntu 13.10 195eb90b5349 3 months ago 184.7 MB
ubuntu saucy 195eb90b5349 3 months ago 184.7 MB
……
87.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
88.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
image name
89.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
image name execute
90.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
image name execute argument
91.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
image name execute argument
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73ec6de5630b ubuntu:14.04 "/bin/echo 'hello, w 2 hours ago Exited (0) sad_engelbart
92.
Run and List container
$ docker run ubuntu:trusty /bin/echo "hello, world"
hello, world
image name execute argument
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
73ec6de5630b ubuntu:14.04 "/bin/echo 'hello, w 2 hours ago Exited (0) sad_engelbart
The container is finished, so we use -a
93.
Run and list running container
docker run ubuntu:latest /bin/sh -c
"while true; do echo hello, world; sleep 1; done;"
hello, world
hello, world
……
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow
94.
Run and list running container
docker run ubuntu:latest /bin/sh -c
"while true; do echo hello, world; sleep 1; done;"
hello, world
hello, world
……
The container is running until we stop it
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8e46bc2bd17d ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow
95.
Run running container in deamon
docker run -d ubuntu:latest /bin/sh -c
"while true; do echo hello, world; sleep 1; done;"
90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow
96.
Run running container in deamon
docker run -d ubuntu:latest /bin/sh -c
"while true; do echo hello, world; sleep 1; done;"
90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow
97.
Run running container in deamon
docker run -d ubuntu:latest /bin/sh -c
"while true; do echo hello, world; sleep 1; done;"
90f0ca0a13014ef82f33a2fbef646d8c2cd2b1b260b0d6e71fc46e553560babb
We use container id to manage it
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90f0ca0a1301 ubuntu:14.04 "/bin/sh -c 2 hours ago Up 5 seconds lonely_brow
98.
Logs and Attach Container
$ docker logs 90f0ca
hello, world
hello, world
……
$ docker attach 90f0ca
hello, world
hello, world
……
99.
Logs and Attach Container
$ docker logs 90f0ca
hello, world
hello, world
……
$ docker attach 90f0ca
hello, world
hello, world
……
Get logs
100.
Logs and Attach Container
$ docker logs 90f0ca
hello, world
hello, world
……
$ docker attach 90f0ca
hello, world
hello, world
……
Get logs
Back to container console
101.
Logs and Attach Container
$ docker logs 90f0ca
hello, world
hello, world
……
$ docker attach 90f0ca
hello, world
hello, world
……
Get logs
Back to container console
「CTRL-p CTRL-q」 to detach.!
102.
Commit
$ docker run -i -t php:5.6.1-apache /bin/bash!
root@4441f36ebab1:/#
You do some change ……
Sets STDIN and open a PTY
103.
Commit
$ docker run -i -t php:5.6.1-apache /bin/bash!
You do some change ……
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse
104.
Commit
$ docker run -i -t php:5.6.1-apache /bin/bash!
You do some change ……
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse
$ docker commit 6a495e871389 fntsr/first-image!
2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df
105.
Commit
$ docker run -i -t php:5.6.1-apache /bin/bash!
You do some change ……
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse
$ docker commit 6a495e871389 fntsr/first-image!
2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df
<username>/<image_name>
106.
Commit
$ docker run -i -t php:5.6.1-apache /bin/bash!
You do some change ……
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a495e871389 php:5-apache "/bin/bash" 24 minutes ago Exited (0) cranky_morse
$ docker commit 6a495e871389 fntsr/first-image!
2006ba62eb6508560ae38782ee514a4212d29ea4e4a2e7495b1eedf155fe13df
$ docker images!
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
fntsr/first-image latest 2006ba62eb65 22 minutes ago 803.6 MB
107.
Expose Port
docker run -d -p 80 nginx
c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp
108.
Expose Port
-p <guest_port>!
docker run -d -p 80 nginx
c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp
109.
Expose Port
-p <guest_port>!
docker run -d -p 80 nginx
c63fda2248d0dcf90a90cc817d1acb6c9546db841128ca7558ff1f496ad4f8fb
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
c63fda2248d0 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:49153->80/tcp
Expose 80 to 49153
(random)
Expose to random port
110.
Expose Port
docker run -d -p 10080:80 nginx
afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp
111.
Expose Port
-p <host_port>:<guest_port>
docker run -d -p 10080:80 nginx
afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp
112.
Expose Port
-p <host_port>:<guest_port>
docker run -d -p 10080:80 nginx
afd45d0f7d34baf90dbef109ae167c99a49432080adc8621e8cd7e18a4004658
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
afd45d0f7d34 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:10080->80/tcp
Expose 80 to 10080
(assigned)
Expose to assigned port
113.
Expose Port
docker run -d -p 127.0.0.1:10080:80 nginx
76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp
114.
Expose Port
-p <hostname>:<host_port>:<guest_port>
docker run -d -p 127.0.0.1:10080:80 nginx
76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp
115.
Expose Port
Expose to host with hostname
-p <hostname>:<host_port>:<guest_port>
docker run -d -p 127.0.0.1:10080:80 nginx
76d00613ccb3576ef604c61f4d086aa6f090ed7268c42638f1931e235c0fe526
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
76d00613ccb3 nginx:1 "nginx… 6 seconds ago Up 5 seconds 443/tcp, 127.0.0.1:10080->80/tcp
Expose with host name
116.
Expose Port
docker run -d -P nginx
2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED PORTS
afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp
117.
Expose Port
-P
docker run -d -P nginx
2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED PORTS
afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp
118.
Expose Port
-P
Expose all port of container !
with host random port
docker run -d -P nginx
2123f55d26fc3d5824492ed8ad4d7f9e28ed5d749e7d401e21a1bb0002f65048
$ docker ps -a!
CONTAINER ID IMAGE COMMAND CREATED PORTS
afd45d0f7d34 nginx:1 "nginx… Up 5 seconds 0.0.0.0:49154->443/tcp, 0.0.0.0:49155->80/tcp
443 expose to 49154
(random)
119.
How could I back to running
container and do another thing?
• attach!
120.
How could I back to running
container and do another thing?
• attach! It can only run one process.
121.
How could I back to running
container and do another thing?
• attach!
• exec
It can only run one process.
122.
How could I back to running
container and do another thing?
• attach!
• exec
It can only run one process.
It's added on docker 1.3 (rock)
123.
Alias
$ docker run nginx --name my-nginx -d nginx
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"
124.
Alias
$ docker run nginx --name my-nginx -d nginx
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"
$ docker exec -it nginx bin/bash
CONTAINER ID IMAGE …… STATUS PORTS NAMES
4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx
125.
$ docker run nginx --name my-nginx -d nginx
4441f36ebab1975004782ea6d03198fd8ced8472cf34721f9906cbebfe61872d"
$ docker exec -it my-nginx bin/bash
root@4441f36ebab1:/#
Alias
$ docker exec -it nginx bin/bash
CONTAINER ID IMAGE …… STATUS PORTS NAMES
4441f36ebab1 nginx:latest Up 4 seconds 443/tcp, 0.0.0.0:80->80/tcp my-nginx
126.
Linking
We don't have enough time…
Let's see picture again! XD
127.
Linking
PHP+Nginx!
Container
Host
MySQL!
Container
Port
Port
128.
Linking
PHP+Nginx!
Container
Host
MySQL!
Container
Port
Port
Let's try to hack!
129.
Linking
PHP+Nginx!
Container
Host
MySQL!
Container
Port
Port
斷開鎖鏈!
130.
Linking
PHP+Nginx!
Container
Host
MySQL!
Container
Port
Link
Port
移情別戀!(不對
131.
Linking
PHP+Nginx!
Container
Host
MySQL!
Container
Port
Link
Oops!
More Secure
152.
Single app container
Volume
PHP App
/var/www/html PHP 5.6
…… Nginx
MySQL
……
Port
153.
Single app container
Volume
PHP App
/var/www/html PHP 5.6
…… Nginx
MySQL
……
Port
Not recommend use for production
154.
Container Groups
Volume /var/www/html
PHP App
…… Nginx
/var/lib/mysql/
……
PHP 5.6
MySQL
……
App Container
DB Container
Port
Port
Easy to manage
155.
Separate containers
FS nginx container
FS
php container
…… PHP-apache
FS MySQL container
…… MySQL
Volume
PHP App
……
Link
Link
Port
…… Nginx
volume
Using in production
156.
Data Only Container
Volume /data
8421917fbed8aa018ad3….
……
/data
……
……
DB-data Container
volume from
DB Container
volume
Los recortes son una forma práctica de recopilar diapositivas importantes para volver a ellas más tarde. Ahora puedes personalizar el nombre de un tablero de recortes para guardar tus recortes.
Crear un tablero de recortes
Compartir esta SlideShare
Oferta especial para lectores de SlideShare
Solo para ti: Prueba exclusiva de 60 días con acceso a la mayor biblioteca digital del mundo.
La familia SlideShare crece. Disfruta de acceso a millones de libros electrónicos, audiolibros, revistas y mucho más de Scribd.