How to install Docker on Linux CentOS 7.9 (Aliyun)

Step 1: Update the system in CentOS 7

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# [root@iZ2zehb3zobkh31kn9cuo2Z ~]# sudo yum check-update

Step 2: download the latest version of Docker, and install it

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# curl -fsSL https://get.docker.com/ | sh
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sh -c 'yum install -y -q yum-utils'
+ sh -c '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
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                                                                                                                              | 3.6 kB  00:00:00
docker-ce-stable                                                                                                                                                                                  | 3.5 kB  00:00:00
epel                                                                                                                                                                                              | 4.7 kB  00:00:00
extras                                                                                                                                                                                            | 2.9 kB  00:00:00
updates                                                                                                                                                                                           | 2.9 kB  00:00:00
(1/13): base/7/x86_64/other_db                                                                                                                                                                    | 2.6 MB  00:00:00
(2/13): base/7/x86_64/filelists_db                                                                                                                                                                | 7.2 MB  00:00:00
(3/13): docker-ce-stable/7/x86_64/updateinfo                                                                                                                                                      |   55 B  00:00:00
(4/13): docker-ce-stable/7/x86_64/filelists_db                                                                                                                                                    |  29 kB  00:00:00
(5/13): docker-ce-stable/7/x86_64/primary_db                                                                                                                                                      |  70 kB  00:00:00
(6/13): epel/x86_64/prestodelta                                                                                                                                                                   | 1.2 kB  00:00:00
(7/13): docker-ce-stable/7/x86_64/other_db                                                                                                                                                        | 122 kB  00:00:00
(8/13): epel/x86_64/filelists_db                                                                                                                                                                  |  12 MB  00:00:00
(9/13): epel/x86_64/other_db                                                                                                                                                                      | 3.4 MB  00:00:00
(10/13): extras/7/x86_64/other_db                                                                                                                                                                 | 145 kB  00:00:00
(11/13): extras/7/x86_64/filelists_db                                                                                                                                                             | 259 kB  00:00:00
(12/13): updates/7/x86_64/other_db                                                                                                                                                                | 937 kB  00:00:00
(13/13): updates/7/x86_64/filelists_db                                                                                                                                                            | 7.2 MB  00:00:00
Metadata Cache Created
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-20.10.12-3.el7.x86_64.rpm is not installed
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
setsebool:  SELinux is disabled.
+ version_gte 20.10
+ '[' -z '' ']'
+ return 0
+ sh -c 'yum install -y -q docker-ce-rootless-extras'
Package docker-ce-rootless-extras-20.10.12-3.el7.x86_64 already installed and latest version

================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

    dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
         to root access on the host. Refer to the 'Docker daemon attack surface'
         documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================

Step 4: Start the docker daemon

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# sudo systemctl start docker

Step 5: Verify the docker is running

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# sudo 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 2022-01-24 20:28:10 CST; 5s ago
     Docs: https://docs.docker.com
 Main PID: 1476 (dockerd)
    Tasks: 8
   Memory: 33.3M
   CGroup: /system.slice/docker.service
           └─1476 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jan 24 20:28:09 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:09.722540746+08:00" level=info msg="scheme \"unix\" not registered, fallback to default scheme" module=grpc
Jan 24 20:28:09 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:09.722556645+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <n...}" module=grpc
Jan 24 20:28:09 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:09.722565841+08:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.302327582+08:00" level=info msg="Loading containers: start."
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.424554009+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option -...ed IP address"
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.464400743+08:00" level=info msg="Loading containers: done."
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.481941444+08:00" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=overlay2 version=20.10.12
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.482026789+08:00" level=info msg="Daemon has completed initialization"
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z systemd[1]: Started Docker Application Container Engine.
Jan 24 20:28:10 iZ2zehb3zobkh31kn9cuo2Z dockerd[1476]: time="2022-01-24T20:28:10.503240656+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ2zehb3zobkh31kn9cuo2Z ~]#

Done!

Hello, Docker!

Create user on Linux CentOS:
linux create user command line: useradd username

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# whoami
root
[root@iZ2zehb3zobkh31kn9cuo2Z ~]# sudo useradd superset_user;

Step 6: Executing Docker Command Without Sudo

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# sudo usermod -aG docker superset_user;

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# docker --version
Docker version 20.10.12, build e91ed57
[root@iZ2zehb3zobkh31kn9cuo2Z ~]# docker

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:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.7.1-docker)
compose* Docker Compose (Docker Inc., v2.2.3)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.12.0)
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
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.

To get more help with docker, check out our guides at Redirecting…
[root@iZ2zehb3zobkh31kn9cuo2Z ~]#

[root@iZ2zehb3zobkh31kn9cuo2Z ~]# su - superset_user
Last login: Mon Jan 24 20:43:24 CST 2022 on pts/1
[superset_user@iZ2zehb3zobkh31kn9cuo2Z ~]$
[superset_user@iZ2zehb3zobkh31kn9cuo2Z ~]$ whoami
superset_user
[superset_user@iZ2zehb3zobkh31kn9cuo2Z ~]$ docker run hello-world

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.
    (amd64)
 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 ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[superset_user@iZ2zehb3zobkh31kn9cuo2Z ~]$
[superset_user@iZ2zehb3zobkh31kn9cuo2Z ~]$ docker --version
Docker version 20.10.12, build e91ed57

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值