docker安装步骤

一、安装依赖

执行命令 sudo yum install -y yum-utils

	[root@iZbp15rmf8lyj2yhq136ebZ ~]# sudo yum install -y yum-utils
	Loaded plugins: fastestmirror
	Determining fastest mirrors
	base                                                                                | 3.6 kB  00:00:00     
	epel                                                                                | 5.3 kB  00:00:00     
	extras                                                                              | 2.9 kB  00:00:00     
	updates                                                                             | 2.9 kB  00:00:00     
	(1/3): epel/x86_64/updateinfo                                                       | 1.0 MB  00:00:00     
	(2/3): epel/x86_64/primary_db                                                       | 6.9 MB  00:00:00     
	(3/3): updates/7/x86_64/primary_db                                                  | 5.8 MB  00:00:00     
	Resolving Dependencies
	--> Running transaction check
	---> Package yum-utils.noarch 0:1.1.31-52.el7 will be installed
	--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-52.el7.noarch
	--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-52.el7.noarch
	--> Running transaction check
	---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed
	---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
	--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
	--> Running transaction check
	---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
	--> Finished Dependency Resolution
	
	Dependencies Resolved
	
	===========================================================================================================
	 Package                      Arch                 Version                        Repository          Size
	===========================================================================================================
	Installing:
	 yum-utils                    noarch               1.1.31-52.el7                  base               121 k
	Installing for dependencies:
	 libxml2-python               x86_64               2.9.1-6.el7_2.3                base               247 k
	 python-chardet               noarch               2.2.1-3.el7                    base               227 k
	 python-kitchen               noarch               1.1.1-5.el7                    base               267 k
	
	Transaction Summary
	===========================================================================================================
	Install  1 Package (+3 Dependent packages)
	
	Total download size: 862 k
	Installed size: 4.3 M
	Downloading packages:
	(1/4): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm                                    | 247 kB  00:00:00     
	(2/4): python-chardet-2.2.1-3.el7.noarch.rpm                                        | 227 kB  00:00:00     
	(3/4): python-kitchen-1.1.1-5.el7.noarch.rpm                                        | 267 kB  00:00:00     
	(4/4): yum-utils-1.1.31-52.el7.noarch.rpm                                           | 121 kB  00:00:00     
	-----------------------------------------------------------------------------------------------------------
	Total                                                                      6.8 MB/s | 862 kB  00:00:00     
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Installing : python-chardet-2.2.1-3.el7.noarch                                                       1/4 
	  Installing : python-kitchen-1.1.1-5.el7.noarch                                                       2/4 
	  Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                   3/4 
	  Installing : yum-utils-1.1.31-52.el7.noarch                                                          4/4 
	  Verifying  : python-kitchen-1.1.1-5.el7.noarch                                                       1/4 
	  Verifying  : yum-utils-1.1.31-52.el7.noarch                                                          2/4 
	  Verifying  : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                   3/4 
	  Verifying  : python-chardet-2.2.1-3.el7.noarch                                                       4/4 
	
	Installed:
	  yum-utils.noarch 0:1.1.31-52.el7                                                                         
	
	Dependency Installed:
	  libxml2-python.x86_64 0:2.9.1-6.el7_2.3                python-chardet.noarch 0:2.2.1-3.el7               
	  python-kitchen.noarch 0:1.1.1-5.el7                   
	
	Complete!

二、指定docker 远程仓库

执行命令 sudo yum-config-manager --add-repo https://download.docker.com/linux/cent

	[root@iZbp15rmf8lyj2yhq136ebZ ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
	Loaded plugins: fastestmirror
	adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
	grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
	repo saved to /etc/yum.repos.d/docker-ce.repo

三、安装docker

执行命令 sudo yum install docker-ce

	[root@iZbp15rmf8lyj2yhq136ebZ ~]# sudo yum install docker-ce
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	docker-ce-stable                                                                    | 3.5 kB  00:00:00     
	(1/2): docker-ce-stable/x86_64/primary_db                                           |  37 kB  00:00:02     
	(2/2): docker-ce-stable/x86_64/updateinfo                                           |   55 B  00:00:02     
	Resolving Dependencies
	--> Running transaction check
	---> Package docker-ce.x86_64 3:19.03.5-3.el7 will be installed
	--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.5-3.el7.x86_64
	--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.5-3.el7.x86_64
	--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.5-3.el7.x86_64
	--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.5-3.el7.x86_64
	--> Running transaction check
	---> Package container-selinux.noarch 2:2.107-3.el7 will be installed
	--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.107-3.el7.noarch
	---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
	---> Package docker-ce-cli.x86_64 1:19.03.5-3.el7 will be installed
	---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
	--> Running transaction check
	---> Package policycoreutils-python.x86_64 0:2.5-33.el7 will be installed
	--> Processing Dependency: policycoreutils = 2.5-33.el7 for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-33.el7.x86_64
	--> Running transaction check
	---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
	--> Processing Dependency: audit-libs(x86-64) = 2.8.5-4.el7 for package: audit-libs-python-2.8.5-4.el7.x86_64
	---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
	---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
	---> Package policycoreutils.x86_64 0:2.5-29.el7_6.1 will be updated
	---> Package policycoreutils.x86_64 0:2.5-33.el7 will be an update
	---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
	---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
	--> Running transaction check
	---> Package audit-libs.x86_64 0:2.8.4-4.el7 will be updated
	--> Processing Dependency: audit-libs(x86-64) = 2.8.4-4.el7 for package: audit-2.8.4-4.el7.x86_64
	---> Package audit-libs.x86_64 0:2.8.5-4.el7 will be an update
	--> Running transaction check
	---> Package audit.x86_64 0:2.8.4-4.el7 will be updated
	---> Package audit.x86_64 0:2.8.5-4.el7 will be an update
	--> Finished Dependency Resolution
	
	Dependencies Resolved
	
	===========================================================================================================
	 Package                         Arch            Version                   Repository                 Size
	===========================================================================================================
	Installing:
	 docker-ce                       x86_64          3:19.03.5-3.el7           docker-ce-stable           24 M
	Installing for dependencies:
	 audit-libs-python               x86_64          2.8.5-4.el7               base                       76 k
	 checkpolicy                     x86_64          2.5-8.el7                 base                      295 k
	 container-selinux               noarch          2:2.107-3.el7             extras                     39 k
	 containerd.io                   x86_64          1.2.10-3.2.el7            docker-ce-stable           23 M
	 docker-ce-cli                   x86_64          1:19.03.5-3.el7           docker-ce-stable           39 M
	 libcgroup                       x86_64          0.41-21.el7               base                       66 k
	 libsemanage-python              x86_64          2.5-14.el7                base                      113 k
	 policycoreutils-python          x86_64          2.5-33.el7                base                      457 k
	 python-IPy                      noarch          0.75-6.el7                base                       32 k
	 setools-libs                    x86_64          3.3.8-4.el7               base                      620 k
	Updating for dependencies:
	 audit                           x86_64          2.8.5-4.el7               base                      256 k
	 audit-libs                      x86_64          2.8.5-4.el7               base                      102 k
	 policycoreutils                 x86_64          2.5-33.el7                base                      916 k
	
	Transaction Summary
	===========================================================================================================
	Install  1 Package  (+10 Dependent packages)
	Upgrade             (  3 Dependent packages)
	
	Total download size: 90 M
	Is this ok [y/d/N]: y
	Downloading packages:
	Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
	(1/14): audit-libs-2.8.5-4.el7.x86_64.rpm                                           | 102 kB  00:00:00     
	(2/14): audit-2.8.5-4.el7.x86_64.rpm                                                | 256 kB  00:00:00     
	(3/14): audit-libs-python-2.8.5-4.el7.x86_64.rpm                                    |  76 kB  00:00:00     
	(4/14): checkpolicy-2.5-8.el7.x86_64.rpm                                            | 295 kB  00:00:00     
	(5/14): container-selinux-2.107-3.el7.noarch.rpm                                    |  39 kB  00:00:00     
	warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.5-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
	Public key for docker-ce-19.03.5-3.el7.x86_64.rpm is not installed
	(6/14): docker-ce-19.03.5-3.el7.x86_64.rpm                                          |  24 MB  00:00:06     
	(7/14): libcgroup-0.41-21.el7.x86_64.rpm                                            |  66 kB  00:00:00     
	(8/14): policycoreutils-2.5-33.el7.x86_64.rpm                                       | 916 kB  00:00:00     
	(9/14): libsemanage-python-2.5-14.el7.x86_64.rpm                                    | 113 kB  00:00:00     
	(10/14): python-IPy-0.75-6.el7.noarch.rpm                                           |  32 kB  00:00:00     
	(11/14): policycoreutils-python-2.5-33.el7.x86_64.rpm                               | 457 kB  00:00:00     
	(12/14): setools-libs-3.3.8-4.el7.x86_64.rpm                                        | 620 kB  00:00:00     
	(13/14): containerd.io-1.2.10-3.2.el7.x86_64.rpm                                    |  23 MB  00:00:10     
	(14/14): docker-ce-cli-19.03.5-3.el7.x86_64.rpm                                     |  39 MB  00:00:17     
	-----------------------------------------------------------------------------------------------------------
	Total                                                                      3.7 MB/s |  90 MB  00:00:24     
	Retrieving key from https://download.docker.com/linux/centos/gpg
	Importing GPG key 0x621E9F35:
	 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
	 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
	 From       : https://download.docker.com/linux/centos/gpg
	 
	Is this ok [y/N]: y
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Updating   : audit-libs-2.8.5-4.el7.x86_64                                                          1/17 
	  Updating   : policycoreutils-2.5-33.el7.x86_64                                                      2/17 
	  Installing : libcgroup-0.41-21.el7.x86_64                                                           3/17 
	  Installing : audit-libs-python-2.8.5-4.el7.x86_64                                                   4/17 
	  Installing : setools-libs-3.3.8-4.el7.x86_64                                                        5/17 
	  Installing : 1:docker-ce-cli-19.03.5-3.el7.x86_64                                                   6/17 
	  Installing : checkpolicy-2.5-8.el7.x86_64                                                           7/17 
	  Installing : python-IPy-0.75-6.el7.noarch                                                           8/17 
	  Installing : libsemanage-python-2.5-14.el7.x86_64                                                   9/17 
	  Installing : policycoreutils-python-2.5-33.el7.x86_64                                              10/17 
	  Installing : 2:container-selinux-2.107-3.el7.noarch                                                11/17 
	setsebool:  SELinux is disabled.
	  Installing : containerd.io-1.2.10-3.2.el7.x86_64                                                   12/17 
	  Installing : 3:docker-ce-19.03.5-3.el7.x86_64                                                      13/17 
	  Updating   : audit-2.8.5-4.el7.x86_64                                                              14/17 
	  Cleanup    : policycoreutils-2.5-29.el7_6.1.x86_64                                                 15/17 
	  Cleanup    : audit-2.8.4-4.el7.x86_64                                                              16/17 
	  Cleanup    : audit-libs-2.8.4-4.el7.x86_64                                                         17/17 
	  Verifying  : audit-libs-2.8.5-4.el7.x86_64                                                          1/17 
	  Verifying  : policycoreutils-python-2.5-33.el7.x86_64                                               2/17 
	  Verifying  : audit-2.8.5-4.el7.x86_64                                                               3/17 
	  Verifying  : 3:docker-ce-19.03.5-3.el7.x86_64                                                       4/17 
	  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                                                   5/17 
	  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                   6/17 
	  Verifying  : 2:container-selinux-2.107-3.el7.noarch                                                 7/17 
	  Verifying  : python-IPy-0.75-6.el7.noarch                                                           8/17 
	  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                           9/17 
	  Verifying  : policycoreutils-2.5-33.el7.x86_64                                                     10/17 
	  Verifying  : containerd.io-1.2.10-3.2.el7.x86_64                                                   11/17 
	  Verifying  : 1:docker-ce-cli-19.03.5-3.el7.x86_64                                                  12/17 
	  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                       13/17 
	  Verifying  : libcgroup-0.41-21.el7.x86_64                                                          14/17 
	  Verifying  : policycoreutils-2.5-29.el7_6.1.x86_64                                                 15/17 
	  Verifying  : audit-2.8.4-4.el7.x86_64                                                              16/17 
	  Verifying  : audit-libs-2.8.4-4.el7.x86_64                                                         17/17 
	
	Installed:
	  docker-ce.x86_64 3:19.03.5-3.el7                                                                         
	
	Dependency Installed:
	  audit-libs-python.x86_64 0:2.8.5-4.el7             checkpolicy.x86_64 0:2.5-8.el7                        
	  container-selinux.noarch 2:2.107-3.el7             containerd.io.x86_64 0:1.2.10-3.2.el7                 
	  docker-ce-cli.x86_64 1:19.03.5-3.el7               libcgroup.x86_64 0:0.41-21.el7                        
	  libsemanage-python.x86_64 0:2.5-14.el7             policycoreutils-python.x86_64 0:2.5-33.el7            
	  python-IPy.noarch 0:0.75-6.el7                     setools-libs.x86_64 0:3.3.8-4.el7                     
	
	Dependency Updated:
	  audit.x86_64 0:2.8.5-4.el7    audit-libs.x86_64 0:2.8.5-4.el7    policycoreutils.x86_64 0:2.5-33.el7   
	
	Complete!

四、验证安装

执行命令

  • 1、sudo docker version 或者 docker –v(查看docker 版本信息)

[root@iZbp15rmf8lyj2yhq136ebZ ~]# sudo docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:25:41 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  • 2、docker 版本简要信息
    执行命令 docker -v

	[root@iZbp15rmf8lyj2yhq136ebZ ~]# docker -v
	Docker version 19.03.5, build 633a0ea

  • 2、docker --help (帮助)
	[root@iZbp15rmf8lyj2yhq136ebZ ~]# docker --help
	
	Usage:	docker [OPTIONS] COMMAND
	
	A self-sufficient runtime for containers
	
	Options:
	      --config string      Location of client config files (default "/root/.docker")
	  -c, --context string     Name of the context to use to connect to the daemon (overrides
	                           DOCKER_HOST env var and default context set with "docker context use")
	  -D, --debug              Enable debug mode
	  -H, --host list          Daemon socket(s) to connect to
	  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default
	                           "info")
	      --tls                Use TLS; implied by --tlsverify
	      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
	      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
	      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
	      --tlsverify          Use TLS and verify the remote
	  -v, --version            Print version information and quit
	
	Management Commands:
	  builder     Manage builds
	  config      Manage Docker configs
	  container   Manage containers
	  context     Manage contexts
	  engine      Manage the docker engine
	  image       Manage images
	  network     Manage networks
	  node        Manage Swarm nodes
	  plugin      Manage plugins
	  secret      Manage Docker secrets
	  service     Manage services
	  stack       Manage Docker stacks
	  swarm       Manage Swarm
	  system      Manage Docker
	  trust       Manage trust on Docker images
	  volume      Manage volumes
	
	Commands:
	  attach      Attach local standard input, output, and error streams to a running container
	  build       Build an image from a Dockerfile
	  commit      Create a new image from a container's changes
	  cp          Copy files/folders between a container and the local filesystem
	  create      Create a new container
	  deploy      Deploy a new stack or update an existing stack
	  diff        Inspect changes to files or directories on a container's filesystem
	  events      Get real time events from the server
	  exec        Run a command in a running container
	  export      Export a container's filesystem as a tar archive
	  history     Show the history of an image
	  images      List images
	  import      Import the contents from a tarball to create a filesystem image
	  info        Display system-wide information
	  inspect     Return low-level information on Docker objects
	  kill        Kill one or more running containers
	  load        Load an image from a tar archive or STDIN
	  login       Log in to a Docker registry
	  logout      Log out from a Docker registry
	  logs        Fetch the logs of a container
	  pause       Pause all processes within one or more containers
	  port        List port mappings or a specific mapping for the container
	  ps          List containers
	  pull        Pull an image or a repository from a registry
	  push        Push an image or a repository to a registry
	  rename      Rename a container
	  restart     Restart one or more containers
	  rm          Remove one or more containers
	  rmi         Remove one or more images
	  run         Run a command in a new container
	  save        Save one or more images to a tar archive (streamed to STDOUT by default)
	  search      Search the Docker Hub for images
	  start       Start one or more stopped containers
	  stats       Display a live stream of container(s) resource usage statistics
	  stop        Stop one or more running containers
	  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
	  top         Display the running processes of a container
	  unpause     Unpause all processes within one or more containers
	  update      Update configuration of one or more containers
	  version     Show the Docker version information
	  wait        Block until one or more containers stop, then print their exit codes
	
	Run 'docker COMMAND --help' for more information on a command.

  • 3、查看某个命令具体配置

	[root@iZbp15rmf8lyj2yhq136ebZ ~]# docker rmi --help
	
	Usage:	docker rmi [OPTIONS] IMAGE [IMAGE...]
	
	Remove one or more images
	
	Options:
	  -f, --force      Force removal of the image
	      --no-prune   Do not delete untagged parents

  • 4、docker详细信息查看
    执行命令docker info
	[root@iZbp15rmf8lyj2yhq136ebZ ~]# docker info
	Client:
	 Debug Mode: false
	
	Server:
	 Containers: 0
	  Running: 0
	  Paused: 0
	  Stopped: 0
	 Images: 0
	 Server Version: 19.03.5
	 Storage Driver: overlay2
	  Backing Filesystem: extfs
	  Supports d_type: true
	  Native Overlay Diff: true
	 Logging Driver: json-file
	 Cgroup Driver: cgroupfs
	 Plugins:
	  Volume: local
	  Network: bridge host ipvlan macvlan null overlay
	  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
	 Swarm: inactive
	 Runtimes: runc
	 Default Runtime: runc
	 Init Binary: docker-init
	 containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
	 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
	 init version: fec3683
	 Security Options:
	  seccomp
	   Profile: default
	 Kernel Version: 3.10.0-957.21.3.el7.x86_64
	 Operating System: CentOS Linux 7 (Core)
	 OSType: linux
	 Architecture: x86_64
	 CPUs: 2
	 Total Memory: 3.701GiB
	 Name: iZbp15rmf8lyj2yhq136ebZ
	 ID: ZOMN:F7HH:AETF:J2DV:YJ62:E7YX:J527:WNU7:PUNP:TQJS:EK4Q:NSII
	 Docker Root Dir: /var/lib/docker
	 Debug Mode: false
	 Registry: https://index.docker.io/v1/
	 Labels:
	 Experimental: false
	 Insecure Registries:
	  127.0.0.0/8
	 Live Restore Enabled: false


五、启动docker

执行命令sudo systemctl start docker


	[root@iZbp15rmf8lyj2yhq136ebZ ~]# sudo systemctl start docker
	
	## 或者 执行
	[root@iZbp15rmf8lyj2yhq136ebZ ~]#  sudo service docker start
	#启动docker
	[root@iZbp15rmf8lyj2yhq136ebZ ~]# service docker start    
	#加入开机启动    
	[root@iZbp15rmf8lyj2yhq136ebZ ~]#  chkconfig docker on         

原文地址:https://www.cnblogs.com/dengxiaoning/p/12063748.html