docker教程之从一头雾水到不一头雾水(1)

一、安装docker

1.搜索docker

[root@node3 ~]# yum search docker
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
========================================================================== N/S matched: docker ===========================================================================
cockpit-docker.x86_64 : Cockpit user interface for Docker containers
docker-client.x86_64 : Client side files for Docker
docker-client-latest.x86_64 : Client side files for Docker
docker-common.x86_64 : Common files for docker and docker-latest
docker-distribution.x86_64 : Docker toolset to pack, ship, store, and deliver content
docker-latest-logrotate.x86_64 : cron job to run logrotate on Docker containers
docker-latest-v1.10-migrator.x86_64 : Calculates SHA256 checksums for docker layer content
docker-logrotate.x86_64 : cron job to run logrotate on Docker containers
docker-lvm-plugin.x86_64 : Docker volume driver for lvm volumes
docker-python.x86_64 : An API client for docker written in Python
docker-registry.noarch : Registry server for Docker
docker-registry.x86_64 : Registry server for Docker
docker-v1.10-migrator.x86_64 : Calculates SHA256 checksums for docker layer content
python-docker-py.noarch : An API client for docker written in Python
python-docker-pycreds.noarch : Python bindings for the docker credentials store API
docker.x86_64 : Automates deployment of containerized applications
docker-devel.x86_64 : A golang registry for global request variables (source libraries)
docker-forward-journald.x86_64 : Forward stdin to journald
docker-latest.x86_64 : Automates deployment of containerized applications
docker-novolume-plugin.x86_64 : Block container starts with local volumes defined
docker-unit-test.x86_64 : Automates deployment of containerized applications - for running unit tests
oci-systemd-hook.x86_64 : OCI systemd hook for docker
oci-umount.x86_64 : OCI umount hook for docker
skopeo.x86_64 : Inspect Docker images and repositories on registries

  Name and summary matches only, use "search all" for everything.

2.安装docker

[root@node3 ~]# yum install -y docker
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.12.6-32.git88a4867.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.12.6-32.git88a4867.el7.centos for package: 2:docker-1.12.6-32.git88a4867.el7.centos.x86_64
....
....
---> Package systemd-libs.x86_64 0:219-30.el7_3.9 will be an update
---> Package systemd-python.x86_64 0:219-19.el7 will be updated
---> Package systemd-python.x86_64 0:219-30.el7_3.9 will be an update
---> Package systemd-sysv.x86_64 0:219-19.el7 will be updated
---> Package systemd-sysv.x86_64 0:219-30.el7_3.9 will be an update
--> Running transaction check
---> Package libgudev1.x86_64 0:219-19.el7 will be updated
---> Package libgudev1.x86_64 0:219-30.el7_3.9 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================
 Package                                       Arch                         Version                                                   Repository                     Size
==========================================================================================================================================================================
Installing:
 docker                                        x86_64                       2:1.12.6-32.git88a4867.el7.centos                         extras                         14 M
Updating:
 selinux-policy-targeted                       noarch                       3.13.1-102.el7_3.16                                       updates                       6.4 M
 systemd                                       x86_64                       219-30.el7_3.9                                            updates                       5.2 M
Installing for dependencies:
 container-selinux                             noarch                       2:2.19-2.1.el7                                            extras                         28 k
 docker-client                                 x86_64                       2:1.12.6-32.git88a4867.el7.centos                         extras                        3.2 M
 docker-common                                 x86_64                       2:1.12.6-32.git88a4867.el7.centos                         extras                         77 k
 oci-register-machine                          x86_64                       1:0-3.11.gitdd0daef.el7                                   extras                        1.0 M
 oci-systemd-hook                              x86_64                       1:0.1.7-4.gite533efa.el7                                  extras                         30 k
 skopeo-containers                             x86_64                       1:0.1.20-2.el7                                            extras                        7.8 k
Updating for dependencies:
 libgudev1                                     x86_64                       219-30.el7_3.9                                            updates                        77 k
 libselinux                                    x86_64                       2.5-6.el7                                                 base                          161 k
 libselinux-devel                              x86_64                       2.5-6.el7                                                 base                          186 k
 libselinux-python                             x86_64                       2.5-6.el7                                                 base                          234 k
 libselinux-utils                              x86_64                       2.5-6.el7                                                 base                          151 k
 libsemanage                                   x86_64                       2.5-5.1.el7_3                                             updates                       144 k
 libsemanage-python                            x86_64                       2.5-5.1.el7_3                                             updates                       104 k
 libsepol                                      x86_64                       2.5-6.el7                                                 base                          288 k
 libsepol-devel                                x86_64                       2.5-6.el7                                                 base                           74 k
 policycoreutils                               x86_64                       2.5-11.el7_3                                              updates                       841 k
 policycoreutils-python                        x86_64                       2.5-11.el7_3                                              updates                       445 k
 selinux-policy                                noarch                       3.13.1-102.el7_3.16                                       updates                       414 k
 setools-libs                                  x86_64                       3.3.8-1.1.el7                                             base                          612 k
 systemd-libs                                  x86_64                       219-30.el7_3.9                                            updates                       369 k
 systemd-python                                x86_64                       219-30.el7_3.9                                            updates                       110 k
 systemd-sysv                                  x86_64                       219-30.el7_3.9                                            updates                        64 k

Transaction Summary
==========================================================================================================================================================================
Install  1 Package  (+ 6 Dependent packages)
Upgrade  2 Packages (+16 Dependent packages)

Total size: 34 M
Total download size: 33 M
Downloading packages:
Delta RPMs reduced 7.0 M of updates to 3.9 M (43% saved)
(1/18): policycoreutils-python-2.2.5-20.el7_2.5-11.el7_3.x86_64.drpm                                                                               | 259 kB  00:00:00     
(2/18): policycoreutils-2.2.5-20.el7_2.5-11.el7_3.x86_64.drpm                                                                                      | 433 kB  00:00:00     
(3/18): systemd-libs-219-19.el7_219-30.el7_3.9.x86_64.drpm                                                                                         | 170 kB  00:00:00     
(4/18): systemd-python-219-19.el7_219-30.el7_3.9.x86_64.drpm                                                                                       |  80 kB  00:00:00     
(5/18): container-selinux-2.19-2.1.el7.noarch.rpm                                                                                                  |  28 kB  00:00:00     
(6/18): docker-client-1.12.6-32.git88a4867.el7.centos.x86_64.rpm                                                                                   | 3.2 MB  00:00:03     
(7/18): docker-common-1.12.6-32.git88a4867.el7.centos.x86_64.rpm                                                                                   |  77 kB  00:00:00     
(8/18): libgudev1-219-30.el7_3.9.x86_64.rpm                                                                                                        |  77 kB  00:00:00     
(9/18): libsemanage-2.5-5.1.el7_3.x86_64.rpm                                                                                                       | 144 kB  00:00:00     
(10/18): libsemanage-python-2.5-5.1.el7_3.x86_64.rpm                                                                                               | 104 kB  00:00:00     
(11/18): systemd-219-19.el7_219-30.el7_3.9.x86_64.drpm                                                                                             | 3.0 MB  00:00:04     
(12/18): oci-register-machine-0-3.11.gitdd0daef.el7.x86_64.rpm                                                                                     | 1.0 MB  00:00:00     
(13/18): oci-systemd-hook-0.1.7-4.gite533efa.el7.x86_64.rpm                                                                                        |  30 kB  00:00:00     
(14/18): skopeo-containers-0.1.20-2.el7.x86_64.rpm                                                                                                 | 7.8 kB  00:00:00     
(15/18): selinux-policy-3.13.1-102.el7_3.16.noarch.rpm                                                                                             | 414 kB  00:00:00     
(16/18): systemd-sysv-219-30.el7_3.9.x86_64.rpm                                                                                                    |  64 kB  00:00:00     
(17/18): selinux-policy-targeted-3.13.1-102.el7_3.16.noarch.rpm                                                                                    | 6.4 MB  00:00:06     
(18/18): docker-1.12.6-32.git88a4867.el7.centos.x86_64.rpm                                                                                         |  14 MB  00:00:14     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                     2.0 MB/s |  30 MB  00:00:14     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libsepol-2.5-6.el7.x86_64                                                                                                                             1/43 
  Updating   : libselinux-2.5-6.el7.x86_64          
....
....                                                                                                                                                                                                                                       42/43 
  Verifying  : policycoreutils-python-2.2.5-20.el7.x86_64                                                                                                           43/43 

Installed:
  docker.x86_64 2:1.12.6-32.git88a4867.el7.centos                                                                                                                         

Dependency Installed:
  container-selinux.noarch 2:2.19-2.1.el7               docker-client.x86_64 2:1.12.6-32.git88a4867.el7.centos   docker-common.x86_64 2:1.12.6-32.git88a4867.el7.centos  
  oci-register-machine.x86_64 1:0-3.11.gitdd0daef.el7   oci-systemd-hook.x86_64 1:0.1.7-4.gite533efa.el7         skopeo-containers.x86_64 1:0.1.20-2.el7                 

Updated:
  selinux-policy-targeted.noarch 0:3.13.1-102.el7_3.16                                           systemd.x86_64 0:219-30.el7_3.9                                          

Dependency Updated:
  libgudev1.x86_64 0:219-30.el7_3.9    libselinux.x86_64 0:2.5-6.el7          libselinux-devel.x86_64 0:2.5-6.el7           libselinux-python.x86_64 0:2.5-6.el7        
  libselinux-utils.x86_64 0:2.5-6.el7  libsemanage.x86_64 0:2.5-5.1.el7_3     libsemanage-python.x86_64 0:2.5-5.1.el7_3     libsepol.x86_64 0:2.5-6.el7                 
  libsepol-devel.x86_64 0:2.5-6.el7    policycoreutils.x86_64 0:2.5-11.el7_3  policycoreutils-python.x86_64 0:2.5-11.el7_3  selinux-policy.noarch 0:3.13.1-102.el7_3.16 
  setools-libs.x86_64 0:3.3.8-1.1.el7  systemd-libs.x86_64 0:219-30.el7_3.9   systemd-python.x86_64 0:219-30.el7_3.9        systemd-sysv.x86_64 0:219-30.el7_3.9        

Complete!
[root@node3 ~]# 

二、启动docker

1.启动命令

[root@node3 ~]# systemctl start docker

2.查看状态

[root@node3 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-08-14 14:34:05 CST; 4s ago
     Docs: http://docs.docker.com
 Main PID: 14321 (dockerd-current)
   CGroup: /system.slice/docker.service
           ├─14321 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdri...
           └─14335 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0...

Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.414920983+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.415711385+08:00" level=warning msg="mountpoint for pids not found"
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.416487662+08:00" level=info msg="Loading containers: start."
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.429707075+08:00" level=info msg="Firewalld running: false"
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.638641730+08:00" level=info msg="Default bridge (docker0) is assigned with an IP addr...P address"
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.780057349+08:00" level=info msg="Loading containers: done."
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.780334779+08:00" level=info msg="Daemon has completed initialization"
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.780367237+08:00" level=info msg="Docker daemon" commit="88a4867/1.12.6" graphdriver=d...ion=1.12.6
Aug 14 14:34:05 node3 dockerd-current[14321]: time="2017-08-14T14:34:05.790544331+08:00" level=info msg="API listen on /var/run/docker.sock"
Aug 14 14:34:05 node3 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@node3 ~]# 

3.查看版本

[root@node3 ~]# docker -version
Client:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-32.git88a4867.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      88a4867/1.12.6
 Built:           Mon Jul  3 16:02:02 2017
 OS/Arch:         linux/amd64

Server:
 Version:         1.12.6
 API version:     1.24
 Package version: docker-1.12.6-32.git88a4867.el7.centos.x86_64
 Go version:      go1.7.4
 Git commit:      88a4867/1.12.6
 Built:           Mon Jul  3 16:02:02 2017
 OS/Arch:         linux/amd64
[root@node3 ~]#

4.查看docker信息

[root@node3 ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.12.6
Storage Driver: devicemapper
 Pool Name: docker-8:1-268507886-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: 11.8 MB
 Data Space Total: 107.4 GB
 Data Space Available: 23.1 GB
 Metadata Space Used: 581.6 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Thin Pool Minimum Free Space: 10.74 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. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.107-RHEL7 (2015-10-14)
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
 Volume: local
 Network: null overlay host bridge
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Security Options: seccomp selinux
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 32
Total Memory: 125.8 GiB
Name: node3
ID: VGL7:LAHR:ETDZ:M7A7:AGJG:HHLV:H4AR:3DY4:3DEA:ZHK4:4DI6:UUZG
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
Insecure Registries:
 127.0.0.0/8
Registries: docker.io (secure)
[root@node3 ~]# 

5.开机自启动

$ sudo chkconfig docker on

三、卸载docker

1.列出已安装的包

$ yum list installed | grep docker
yum list installed | grep docker
docker-engine.x86_64   1.7.1-1.el7 @/docker-engine-1.7.1-1.el7.x86_64.rpm

2.删除安装包

$ sudo yum -y remove docker-engine.x86_64

3.删除镜像/容器等

$ rm -rf /var/lib/docker

四、安装docker镜像

1.docker镜像地址

官方:https://hub.docker.com/

国内网易:https://c.163.com/hub#/m/home/

2.安装centos镜像

以官方地址为例,打开网址,首页搜索centos,点击第一个,因为star最多嘛

复制右上角的命令到命令行执行

[root@ichz ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
7dc0dca2b151: Pull complete
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for docker.io/centos:latest
[root@ichz ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              49f7960eb7e4        9 days ago          200 MB

好了,centos镜像就安装好了。

参考文章

https://blog.csdn.net/chengyuqiang/article/details/78886986

https://blog.csdn.net/a527219336/article/details/50800181

posted @ 2018-06-15 23:32  夏威夷8080  阅读(313)  评论(0编辑  收藏  举报