docker for CentOS 7 installation

1. Install CentOS 7 64bit

   Make sure the centos minimum kernel version is 3.10 and above

 

$ uname -r
3.10.0-229.el7.x86_64

2. Install Docker (yum installation)

2.1. Create a docker user

 

2.2. Add the docker user to the sudoers file

    #vim /etc/sudoers find this line: "root ALL=(ALL) ALL", add below it

    docker ALL=(ALL) ALL

 

3. Install docker

 

3.1. Log into your machine as a user with sudo or root privileges.

3.2. Make sure your existing yum packages are up-to-date.

$ sudo yum update

3.3.  Add the yum repo.

$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

   

3.4. Install the Docker package.

$ sudo yum install docker-engine

[docker@localhost ~]$ sudo yum install docker-engine
[sudo] password for docker:
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00    
dockerrepo                                               | 2.9 kB     00:00    
extras                                                   | 3.4 kB     00:00    
updates                                                  | 3.4 kB     00:00    
(1/3): extras/7/x86_64/primary_db                                       | 165 kB  00:00:01    
(2/3): dockerrepo/primary_db                                            |  20 kB  00:00:01    
(3/3): updates/7/x86_64/primary_db                                      | 7.8 MB  00:04:32    
Determining fastest mirrors
 * base: mirrors.sina.cn
 * extras: mirrors.cn99.com
 * updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:1.12.1-1.el7.centos will be installed
--> Processing Dependency: docker-engine-selinux >= 1.12.1-1.el7.centos for package: docker-engine-1.12.1-1.el7.centos.x86_64
--> Running transaction check
---> Package docker-engine-selinux.noarch 0:1.12.1-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================
 Package                      Arch          Version                    Repository         Size
===============================================================================================
Installing:
 docker-engine                x86_64        1.12.1-1.el7.centos        dockerrepo         19 M
Installing for dependencies:
 docker-engine-selinux        noarch        1.12.1-1.el7.centos        dockerrepo         28 k

Transaction Summary
===============================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 19 M
Installed size: 79 M
Is this ok [y/d/N]: y(输入 y)

 

Downloading packages:
warning: /var/cache/yum/x86_64/7/dockerrepo/packages/docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY
Public key for docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm is not installed
(1/2): docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm                                                          |  28 kB  00:00:01    
(2/2): docker-engine-1.12.1-1.el7.centos.x86_64.rpm                                                                  |  19 MB  00:01:05    
--------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                       295 kB/s |  19 MB  00:01:05    
Retrieving key from https://yum.dockerproject.org/gpg
Importing GPG key 0x2C52609D:
 Userid     : "Docker Release Tool (releasedocker) <[email protected]>"
 Fingerprint: 5811 8e89 f3a9 1289 7c07 0adb f762 2157 2c52 609d
 From       : https://yum.dockerproject.org/gpg
Is this ok [y/N]: y(输入 y)

 

Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : docker-engine-selinux-1.12.1-1.el7.centos.noarch                                                                         1/2
restorecon:  lstat(/var/lib/docker) failed:  No such file or directory
warning: %post(docker-engine-selinux-1.12.1-1.el7.centos.noarch) scriptlet failed, exit status 255
Non-fatal POSTIN scriptlet failure in rpm package docker-engine-selinux-1.12.1-1.el7.centos.noarch
  Installing : docker-engine-1.12.1-1.el7.centos.x86_64                                                                                 2/2
  Verifying  : docker-engine-selinux-1.12.1-1.el7.centos.noarch                                                                         1/2
  Verifying  : docker-engine-1.12.1-1.el7.centos.x86_64                                                                                 2/2

Installed:
  docker-engine.x86_64 0:1.12.1-1.el7.centos                                                                                               

Dependency Installed:
  docker-engine-selinux.noarch 0:1.12.1-1.el7.centos                                                                                       

Complete!

 

3.5. Start the Docker daemon.

$ sudo service docker start
[sudo] password for docker: 输入密码(root)
Redirecting to /bin/systemctl start  docker.service

3.6. Verify docker is installed correctly by running a test image in a container.

$ sudo docker run hello-world
   Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

 

 

3.7. View image information

[docker@localhost ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              c54a2cc56cbb        12 weeks ago        1.848 kB


3.8. Get the details of an image

[docker@localhost ~]$ docker inspect c54a2cc56cbb ( 即 IMAGE ID  )
[
    {
        "Id": "sha256:c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc",
        "RepoTags": [
            "hello-world:latest"
        ],
        "RepoDigests": [
            "hello-world@sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9"
        ],
        "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-8:3-37159125-ff753638d0db8bd72bf5fdaee2daf93d080e9147197b2936e044717d417f18b9",
                "DeviceSize": "10737418240"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:a02596fdd012f22b03af6ad7d11fa590c57507558357b079c3e8cebceb4262d7"
            ]
        }
    }
]

 

4. docker upgrade

4.1. Check Docker version

[docker@localhost ~]$ docker -v
Docker version 1.12.1, build 23cf638

 

4.2. Stop Docker , if Docker is running, stop it first.
[docker@localhost ~]$ sudo systemctl stop docker
[sudo] password for docker: enter password (root)

4.3. 升级docker
[docker@localhost ~]$ sudo yum -y update docker

Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                 | 3.6 kB  00:00:00    
dockerrepo                                                                                                           | 2.9 kB  00:00:00    
extras                                                                                                               | 3.4 kB  00:00:00    
updates                                                                                                              | 3.4 kB  00:00:00    
(1/2): extras/7/x86_64/primary_db                                                                                    | 166 kB  00:00:00    
(2/2): updates/7/x86_64/primary_db                                                                                   | 7.8 MB  00:00:05    
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Package(s) docker available, but not installed.
No packages marked for update

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327034372&siteId=291194637
Recommended