Getting Started with Docker
아~ 대충 이런거구나!!
Goal...
내 PC에 리눅스를 돌려보자!
Mission...
질문은 안받습니다!
그냥 따라하세요 ㅋㅋ
Rules...
Installing Docker
Step 1
- On Ubuntu
- On Red Hat and family
- On OS X
install Boot2Docker
- On Microsoft Windows
install Boot2Docker
$ sudo apt-get install lxc-docker
$ sudo yum -y install lxc-docker
Installing Boot2Docker
-
http://boot2docker.io 에서
pkg, exe 파일 다운로드 받은 후 설치
-
installation documentaion 따라하기
-
$ boot2docker init
-
$ boot2docker start
-
$ $(boot2docker shellinit)
-
Testing Boot2Docker
-
$ docker info
-
$ docker version
-
$ boot2docker
-
$ boot2docker ip
$ docker info
Containers: 0
Images: 0
Storage Driver: aufs
Root Dir: /mnt/sda1/var/lib/docker/aufs
Dirs: 0
Execution Driver: native-0.2
Kernel Version: 3.16.4-tinycore64
Operating System: Boot2Docker 1.3.0 (TCL 5.4); master : a083df4 - Thu Oct 16 17:05:03 UTC 2014
Debug mode (server): true
Debug mode (client): false
Fds: 10
Goroutines: 11
EventsListeners: 0
Init Path: /usr/local/bin/docker
$ 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): darwin/amd64
Server version: 1.3.0
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): c78088f
$ boot2docker
Usage: boot2docker [<options>] {help|init|up|ssh|save|down|poweroff|reset|restart|config|status|info|ip|socket|shellinit|delete|download|upgrade|version} [<args>]
$ boot2docker ip
The VM's Host only interface IP address is: 192.168.59.103
Build our first container
Step 2
$ docker run -i -t ubuntu /bin/bash
$ docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu' locally
ubuntu:latest: The image you are pulling has been verified
511136ea3c5a: Pull complete
d497ad3926c8: Downloading [==========================> d497ad3926c8: Pull complete
ccb62158e970: Pull complete
e791be0477f2: Pull complete
3680052c0f5c: Pull complete
22093c35d77b: Pull complete
5506de2b643b: Pull complete
Status: Downloaded newer image for ubuntu:latest
root@2e0f473304c5:/#
Working with
our first container
Step 3
- hostname 확인
root@2e0f473304c5:/# hostname
- /etc/hosts 파일 확인
root@2e0f473304c5:/# cat /etc/hosts
- 네트워크 설정 확인
root@2e0f473304c5:/# ip a
- 실행중인 프로세스 확인
root@2e0f473304c5:/# ps -aux
- 패키지 설치
root@2e0f473304c5:/# apt-get update && apt-get install
root@2e0f473304c5:/# hostname
2e0f473304c5
root@2e0f473304c5:/# cat /etc/hosts
172.17.0.2 2e0f473304c5
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1 localhost
root@2e0f473304c5:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
6: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
valid_lft forever preferred_lft forever
root@2e0f473304c5:/# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 18172 3336 ? Ss 01:11 0:00 /bin/bash
root 20 0.0 0.1 15572 2168 ? R+ 01:14 0:00 ps -aux
root@2e0f473304c5:/# apt-get update && apt-get install
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Ign http://archive.ubuntu.com trusty-proposed InRelease
Get:1 http://archive.ubuntu.com trusty Release.gpg [933 B]
Get:2 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
Get:3 http://archive.ubuntu.com trusty-security Release.gpg [933 B]
Get:4 http://archive.ubuntu.com trusty-proposed Release.gpg [933 B]
Get:5 http://archive.ubuntu.com trusty Release [58.5 kB]
Get:6 http://archive.ubuntu.com trusty-updates Release [59.7 kB]
Get:7 http://archive.ubuntu.com trusty-security Release [59.7 kB]
Get:8 http://archive.ubuntu.com trusty-proposed Release [110 kB]
Get:9 http://archive.ubuntu.com trusty/main Sources [1335 kB]
Get:10 http://archive.ubuntu.com trusty/restricted Sources [5335 B]
Get:11 http://archive.ubuntu.com trusty/universe Sources [7926 kB]
Get:12 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB]
Get:13 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB]
Get:14 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB]
Get:15 http://archive.ubuntu.com trusty-updates/main Sources [173 kB]
Get:16 http://archive.ubuntu.com trusty-updates/restricted Sources [1250 B]
Get:17 http://archive.ubuntu.com trusty-updates/universe Sources [110 kB]
Get:18 http://archive.ubuntu.com trusty-updates/main amd64 Packages [447 kB]
Get:19 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [6341 B]
Get:20 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [280 kB]
Get:21 http://archive.ubuntu.com trusty-security/main Sources [58.9 kB]
Get:22 http://archive.ubuntu.com trusty-security/restricted Sources [40 B]
Get:23 http://archive.ubuntu.com trusty-security/universe Sources [11.8 kB]
Get:24 http://archive.ubuntu.com trusty-security/main amd64 Packages [192 kB]
Get:25 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [40 B]
Get:26 http://archive.ubuntu.com trusty-security/universe amd64 Packages [62.4 kB]
Get:27 http://archive.ubuntu.com trusty-proposed/main amd64 Packages [171 kB]
Get:28 http://archive.ubuntu.com trusty-proposed/restricted amd64 Packages [40 B]
Fetched 20.4 MB in 27s (756 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
root@2e0f473304c5:/#
Container naming
Step 4
$ docker run --name my_ubuntu -i -t ubuntu /bin/bash
$ docker run --name my_ubuntu -i -t ubuntu /bin/bash
root@9ea32e787155:/# exit
exit
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
9ea32e787155 ubuntu:latest "/bin/bash" 45 seconds ago Exited (0) 40 seconds ago my_ubuntu
2e0f473304c5 ubuntu:latest "/bin/bash" 10 minutes ago Exited (130) 4 minutes ago prickly_nobel
Starting a stopped container
Step 5
$ docker start my_ubuntu
$ docker start my_ubuntu
my_ubuntu
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
e2ef689fbd48 ubuntu:latest "/bin/bash" 28 seconds ago Up 3 seconds my_ubuntu
2e0f473304c5 ubuntu:latest "/bin/bash" 15 minutes ago Exited (130) 9 minutes ago prickly_nobel
$ docker start 2e0f473304c5
$ docker start 2e0f473304c5
2e0f473304c5
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
e2ef689fbd48 ubuntu:latest "/bin/bash" 52 seconds ago Up 27 seconds my_ubuntu
2e0f473304c5 ubuntu:latest "/bin/bash" 16 minutes ago Up 6 seconds prickly_nobel
Creating daemonized container
Step 6
$ docker run --name my_daemon -d -i -t ubuntu /bin/sh -c "....."
$ docker run --name my_daemon -d ubuntu /bin/sh -c \
> "while true; do echo hello world; sleep 1; done"
701f707500362ffa82451a45bc85d3d591542e632745e3d8a5d531ddfac56fd5
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
701f70750036 ubuntu:latest "/bin/sh -c 'while t 18 seconds ago Up 18 seconds my_daemon
Seeing what's happening inside our container
Step 7
$ docker logs my_daemon
$ docker logs my_daemon
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
$ docker logs -f my_daemon
$ docker logs -f my_daemon
hello world
hello world
hello world
. . .
$ docker logs -ft my_daemon
$ docker logs -ft my_daemon
[2014-10-31T01:48:29.746942182Z] hello world
[2014-10-31T01:48:30.753369401Z] hello world
[2014-10-31T01:48:32.757641439Z] hello world
. . .
Inspecting the container's processes
Step 8
$ docker top my_daemon
$ docker top my_daemon
PID USER COMMAND
1658 root /bin/sh -c while true; do echo hello world; sleep 1; done
2342 root sleep 1
Stopping a daemonized container
Step 9
$ docker stop my_daemon
$ docker stop my_daemon
my_daemon
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
701f70750036 ubuntu:latest "/bin/sh -c 'while t 15 minutes ago Exited (-1) 27 seconds ago my_daemon
Finding out more about our container
Step 10
$ docker inspect my_daemon
$ docker inspect my_daemon
[{
"Args": [
"-c",
"while true; do echo hello world; sleep 1; done"
],
"Config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": [
"/bin/sh",
"-c",
"while true; do echo hello world; sleep 1; done"
],
"CpuShares": 0,
"Cpuset": "",
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"ExposedPorts": null,
"Hostname": "701f70750036",
"Image": "ubuntu",
"Memory": 0,
"MemorySwap": 0,
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"PortSpecs": null,
"SecurityOpt": null,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": null,
"WorkingDir": ""
},
"Created": "2014-10-31T01:39:11.567035219Z",
"Driver": "aufs",
"ExecDriver": "native-0.2",
"HostConfig": {
"Binds": null,
"CapAdd": null,
"CapDrop": null,
"ContainerIDFile": "",
"Devices": [],
"Dns": null,
"DnsSearch": null,
"ExtraHosts": null,
"Links": null,
"LxcConf": [],
"NetworkMode": "bridge",
"PortBindings": {},
"Privileged": false,
"PublishAllPorts": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": ""
},
"VolumesFrom": null
},
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/701f707500362ffa82451a45bc85d3d591542e632745e3d8a5d531ddfac56fd5/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/701f707500362ffa82451a45bc85d3d591542e632745e3d8a5d531ddfac56fd5/hosts",
"Id": "701f707500362ffa82451a45bc85d3d591542e632745e3d8a5d531ddfac56fd5",
"Image": "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5",
"MountLabel": "",
"Name": "/my_daemon",
"NetworkSettings": {
"Bridge": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"MacAddress": "",
"PortMapping": null,
"Ports": null
},
"Path": "/bin/sh",
"ProcessLabel": "",
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/701f707500362ffa82451a45bc85d3d591542e632745e3d8a5d531ddfac56fd5/resolv.conf",
"State": {
"ExitCode": -1,
"FinishedAt": "2014-10-31T01:53:58.481142418Z",
"Paused": false,
"Pid": 0,
"Restarting": false,
"Running": false,
"StartedAt": "2014-10-31T01:39:11.792736481Z"
},
"Volumes": {},
"VolumesRW": {}
}
]%
$ docker inspect -f '{{ .State.Running }}' my_daemon
$ docker inspect -f '{{ .State.Running }}' my_daemon
false
$ docker inspect -f '{{ .State.ExitCode }}' my_daemon
$ docker inspect -f '{{ .NetworkSettings }}' my_daemon
map[PortMapping:<nil> Ports:<nil> Bridge: Gateway: IPAddress: IPPrefixLen:0 MacAddress:]
$ docker inspect -f '{{ .NetworkSettings }}' my_daemon
$ docker inspect -f '{{ .State.ExitCode }}' my_daemon
-1
$ docker inspect -f '{{.Name}} {{.State.Running}}' \ my_ubuntu my_daemon
$ docker inspect -f '{{.Name}} {{.State.Running}}' my_ubuntu my_daemon
/my_ubuntu true
/my_daemon false
Deleting a container
Step 11
$ docker rm my_daemon
$ docker rm my_daemon
my_daemon
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Play with Docker!
Getting Started with Docker
By bbugguj
Getting Started with Docker
- 1,127