Docker--第一节实验文档
目录
一、安装docker
docker version
[root@localhost ~]# docker version
Client:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 21:23:11 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 21:23:11 2016
OS/Arch: linux/amd64
[root@localhost ~]#
docker info
[root@localhost ~]# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 1.11.2
Storage Driver: devicemapper
Pool Name: docker-253:0-136708049-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 19.4 MB
Data Space Total: 107.4 GB
Data Space Available: 49.19 GB
Metadata Space Used: 593.9 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2015-10-14)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge null host
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 977.9 MiB
Name: localhost
ID: KT34:JS2W:4X7Y:TRTX:47XQ:2NYV:NH7I:XKE5:CNMQ:2QB2:7LTN:LYNG
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]#
docker images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest c54a2cc56cbb 2 weeks ago 1.848 kB
二、使用和管理本地主机上的 images
1.获取 images
[root@localhost ~]# docker pull imagine10255/centos6-lnmp-php56
Using default tag: latest
latest: Pulling from imagine10255/centos6-lnmp-php56
9614861c9275: Downloading 23.77 MB/68.73 MB
176fd9290208: Downloading 24.41 MB/33.26 MB
eaa7f57f6837: Downloading 17.83 MB/122.5 MB
531b95aaf62b: Waiting
bb8dcc5b2136: Waiting
05a908cdab97: Waiting
7381cb9cef99: Waiting
3ce32efa3b7b: Waiting
9b30b4dd1d27: Waiting
6a5052f71361: Waiting
9ca6965d3b35: Waiting
58adb880dfc2: Waiting
b05e5192bd5d: Waiting
b1fc95cfe2cf: Waiting
0b294abea4b6: Waiting
3e156be605ee: Waiting
3acb4c8361c0: Waiting
766c00ac2d13: Waiting
68206a60c40c: Waiting
aab695794dbf: Waiting
8a46f63c7dc2: Waiting
a409fd3832ac: Waiting
b380c924c37a: Waiting
b380c924c37a: Pulling fs layer
2.查找 images
[root@localhost ~]# docker search centos6
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 10 [OK]
lemonbar/centos6-ssh Installed openssh-server on centos6, defau... 7 [OK]
sktelecom/centos6-hdw 2 [OK]
sergeyzh/centos6-nginx 2 [OK]
guyton/centos6 From official centos6 container with full ... 2 [OK]
edrans/centos6 1 [OK]
treasureboat/centos6 CentOS 6.6 updated version 1 [OK]
babim/centos6-gui centos6-gui 0 [OK]
hidetarou2013/centos6-apache centos6-apache 0 [OK]
jeongho/centos6 Docker image for centos6 0 [OK]
airdock/node-centos6 Docker Image for Node.js on Centos 6 0 [OK]
alljoynsville/centos6-32 centos6 build essential with 32bit build libs 0 [OK]
tnanba/centos6-rpmbuild CentOS6 + Development Tools + rpmbuild env... 0 [OK]
nathankw/centos6 Base image is centos:centos6. Python 2.7.1... 0 [OK]
hgomez/di-centos6-base 0 [OK]
imagine10255/centos6-mariadb centos6+mariadb10 0 [OK]
libero18/centos6 0 [OK]
gibby/centos6-supervisor Supervisor on CentOS6 0 [OK]
rjeschmi/easybuild-centos6 The basic EasyBuild starting point: Centos... 0 [OK]
miko2u/centos6 CentOS6 日本語環境 0 [OK]
caio2k/centos6 centos6 with supervisord, ssh and vagrant ... 0 [OK]
miko2u/centos6-rpmbuild RPMBuilder for CentOS6 0 [OK]
weepee/centos6 0 [OK]
opencpu/centos6 Development build of OpenCPU based on Cent... 0 [OK]
tnanba/centos6-devtools CentOS6 + Development Tools 0 [OK]
[root@localhost ~]#
3.查看完整信息
docker inspect
[root@localhost ~]# docker inspect hello-world
[
{
"Id": "sha256:c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc",
"RepoTags": [
"hello-world:latest"
],
"RepoDigests": [],
"Parent": "",
"Comment": "",
"Created": "2016-07-01T19:39:27.532838486Z",
"Container": "562cadb4d17bbf30b58ab0f6a870be60c8d36d2e401bf637f1d2d7f8afbef666",
"ContainerConfig": {
"Hostname": "c65bc554a4b7",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) CMD [\"/hello\"]"
],
"Image": "sha256:0f9bb7da10de694b2babd0c1a3b75582a0db3395625cae5ab0fe537ce1cd831e",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "1.10.3",
"Author": "",
"Config": {
"Hostname": "c65bc554a4b7",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/hello"
],
"Image": "sha256:0f9bb7da10de694b2babd0c1a3b75582a0db3395625cae5ab0fe537ce1cd831e",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 1848,
"VirtualSize": 1848,
"GraphDriver": {
"Name": "devicemapper",
"Data": {
"DeviceId": "2",
"DeviceName": "docker-253:0-136708049-cc5cee17c6c1671ebcf2e97af050612a1a64300f4f804375de04fc52b46a2cfa",
"DeviceSize": "10737418240"
}
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:a02596fdd012f22b03af6ad7d11fa590c57507558357b079c3e8cebceb4262d7"
]
}
}
]
[root@localhost ~]#
docker imges --no-trunc
[root@localhost ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest sha256:c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc 2 weeks ago 1.848 kB
[root@localhost ~]#
三、创建我们自己的 images
1. 基于已有镜像的容器创建
该方法主要是使用 docker commit 命令, 其命令格式为 docker commit[ OPTIONS] CONTAINER[ REPOSITORY[: TAG]], 主要选项包括:
-a,-- author=""作者信息。-m,-- message=""提交消息。-p,-- pause= true提交时暂停容器运行。
[root@localhost ~]# docker run -it centos6:import /bin/bash
[root@3b0867d0634e /]#
使用上面的ID来创建
[root@localhost ~]# docker commit -m "Added openssl-devel" -a "jason" 3b0867d0634e test
sha256:7342f6ece25fdbfefc6daa31411f7cf62f9faf464f8f8185095b585d9a64a842
[root@localhost ~]#
创建好之后,查看images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test latest 7342f6ece25f 4 minutes ago 613.9 MB
centos6 import d7fc899015d9 21 minutes ago 613.9 MB
hello-world latest c54a2cc56cbb 2 weeks ago 1.848 kB
[root@localhost ~]#
2.基于本地模板导入
事先现在好了的模板 centos-6-x86_64.tar.gz 已经上传到虚拟机
[root@localhost ~]# ls
anaconda-ks.cfg Desktop Documents Music Public Videos
centos-6-x86_64.tar.gz docker.repo Downloads Pictures Templates
[root@localhost ~]#
[root@localhost ~]# cat centos-6-x86_64.tar.gz | docker import - centos6:import
sha256:d7fc899015d969390ca6a2333cd74843c16560389e6c9c1a6dfe01bc42b1e406
[root@localhost ~]#
3.使用Dockerfile创建镜像
# This dockerfile uses the ubuntu image
# VERSION 2 - EDITION 1 # Author: docker_ user
# Command format: Instruction [arguments / command] ..
# 第一行必须指定基于的基础镜像
FROM ubuntu
# 维护者信息
MAINTAINER docker_ user docker_ user@ email. com
# 镜像的操作指令
RUN echo "deb http:// archive. ubuntu. com/ ubuntu/ raring main universe" >> /etc/ apt/ sources. list RUN apt- get update && apt- get install -y nginx RUN echo "\ndaemon off;" >> /etc/ nginx/ nginx. conf
# 容器 启动 时 执行 指令 CMD /usr/ sbin/ nginx
[root@webmin httpd]# cat Dockerfile
#This is a comment
FROM centos6:import
MAINTAINER jason
RUN yum -q -y install mysql-server
[root@webmin httpd]#
四、Docker 容器
1.新建并启动
[root@localhost ~]# docker run -it centos6:import /bin/bash
[root@c5ce00e3d33c /]# mount /dev/cdrom /mnt
mount: you must specify the filesystem type
[root@c5ce00e3d33c /]# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 10G 674M 9.4G 7% /
/dev/mapper/docker-253:0-136708049-b57a2e1dfee051a9564f68ab7048f80e1befe7a94f984518fc7ac7647ae32813
10G 674M 9.4G 7% /
tmpfs 489M 0 489M 0% /dev
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mapper/centos-root
50G 5.1G 45G 11% /etc/resolv.conf
/dev/mapper/centos-root
50G 5.1G 45G 11% /etc/hostname
/dev/mapper/centos-root
50G 5.1G 45G 11% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 489M 0 489M 0% /proc/kcore
tmpfs 489M 0 489M 0% /proc/timer_stats
tmpfs 489M 0 489M 0% /proc/sched_debug
[root@c5ce00e3d33c /]# cd /etc/yum.repos.d/
[root@c5ce00e3d33c yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-fasttrack.repo
[root@c5ce00e3d33c yum.repos.d]# rpm -qa | grep openssl
openssl-1.0.1e-42.el6_7.4.x86_64
2.容器内安装 openssl-devel
[root@c5ce00e3d33c yum.repos.d]# rpm -qa | grep openssl-devel
[root@c5ce00e3d33c yum.repos.d]# yum -y install openssl-devel
Loaded plugins: fastestmirror
Setting up Install Process
base | 3.7 kB 00:00
base/primary_db | 4.7 MB 00:01
extras | 3.4 kB 00:00
extras/primary_db | 37 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 1.4 MB 00:01
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64 0:1.0.1e-48.el6_8.1 will be installed
--> Processing Dependency: openssl = 1.0.1e-48.el6_8.1 for package: openssl-devel-1.0.1e-48.el6_8.1.x86_64
--> Processing Dependency: zlib-devel for package: openssl-devel-1.0.1e-48.el6_8.1.x86_64
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-48.el6_8.1.x86_64
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.10.3-57.el6 will be installed
..//省略
---> Package libselinux-utils.x86_64 0:2.0.94-5.8.el6 will be updated
---> Package libselinux-utils.x86_64 0:2.0.94-7.el6 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
openssl-devel x86_64 1.0.1e-48.el6_8.1 updates 1.2 M
Installing for dependencies:
keyutils-libs-devel x86_64 1.4-5.el6 base 29 k
krb5-devel x86_64 1.10.3-57.el6 base 504 k
libcom_err-devel x86_64 1.41.12-22.el6 base 33 k
libselinux-devel x86_64 2.0.94-7.el6 base 137 k
libsepol-devel x86_64 2.0.41-4.el6 base 64 k
zlib-devel x86_64 1.2.3-29.el6 base 44 k
Updating for dependencies:
krb5-libs x86_64 1.10.3-57.el6 base 770 k
libselinux i686 2.0.94-7.el6 base 109 k
libselinux x86_64 2.0.94-7.el6 base 109 k
libselinux-utils x86_64 2.0.94-7.el6 base 82 k
openssl x86_64 1.0.1e-48.el6_8.1 updates 1.5 M
Transaction Summary
======================================================================================================
..//省略
Complete!
[root@c5ce00e3d33c yum.repos.d]#