admin 管理员组文章数量: 887053
2024年1月5日发(作者:cda太卡怎么办)
Docker基础安装使用
2020-02-22
作者:刘子毅
创建yum源
[root@bogon ~]#
[root@bogon ~]# yum-config-manager --add-repo
/linux/centos/
Loaded plugins: fastestmirror, langpacks
adding repo from: /linux/centos/
grabbing file /linux/centos/ to
/etc/.d/
Could not fetch/save url /linux/centos/ to file
/etc/.d/: [Errno 14] curl#7 - "Failed connect to
:443; Operation now in progress"
[root@bogon ~]#
[root@bogon ~]#
链接无法解析改为使用阿里的yum源,操作如下:
[root@bogon ~]# yum-config-manager --add-repo
/docker-ce/linux/centos/
Loaded plugins: fastestmirror, langpacks
adding repo from: /docker-ce/linux/centos/
grabbing file /docker-ce/linux/centos/ to
/etc/.d/
repo saved to /etc/.d/
安装最新的docker
[root@bogon ~]#
[root@bogon ~]# yum install docker-ce
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/: another copy is running as pid 9034.
Another app is currently holding the yum lock; waiting for it
The other application is: PackageKit
Memory : 119 M RSS (1.0 GB VSZ)
Started: Fri Feb 21 19:28:47 2020 - 07:27 ago
State : Sleeping, pid: 9034
Another app is currently holding the yum lock; waiting for it
The other application is: PackageKit
Memory : 119 M RSS (1.0 GB VSZ)
Started: Fri Feb 21 19:28:47 2020 - 07:29 ago
State : Sleeping, pid: 9034
Another app is currently holding the yum lock; waiting for it
The other application is: PackageKit
Memory : 119 M RSS (1.0 GB VSZ)
Started: Fri Feb 21 19:28:47 2020 - 08:12 ago
State : Sleeping, pid: 9034
^C
Exiting on user cancel.
此处发下yum被进程号为9034占用,直接kill
[root@bogon ~]# ps aux | grep yum
root 9034 2.5 12.2 1041184 121668 ? SN 19:28 0:13 /usr/bin/python
/usr/share/PackageKit/helpers/yum/ get-updates none
root 10322 0.0 0.0 112708 976 pts/0 S+ 19:37 0:00 grep --color=auto
yum
[root@bogon ~]# kill -9 9034
[root@bogon ~]# ps aux | grep yum
root 10338 0.0 0.0 112708 976 pts/0 R+ 19:37 0:00 grep --color=auto
yum
[root@bogon ~]#
[root@bogon ~]#
[root@bogon ~]#
[root@bogon ~]#
重新安装docker,如下:
[root@bogon ~]# yum install docker-ce
BDB2053 Freeing read locks for locker 0x9ba: 9034/140
BDB2053 Freeing read locks for locker 0x9bc: 9034/140
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base:
* extras:
* updates:
docker-ce-stable
| 3.5 kB 00:00:00
(1/2): docker-ce-stable/x86_64/primary_db
| 38 kB 00:00:00
(2/2): docker-ce-stable/x86_64/updateinfo
| 55 B 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package:
3:7.x86_64
--> Processing Dependency: >= 1.2.2-3 for package:
3:7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:7.x86_64
--> Running transaction check
---> Package 2:7 will be installed
---> Package .x86_64 0:7 will be installed
---> Package docker-ce-cli.x86_64 1:7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================
Package Arch Version
Repository Size
============================================================================================================================================
Installing:
docker-ce x86_64 3:7
docker-ce-stable 24 M
Installing for dependencies:
container-selinux noarch 2:7
extras 39 k
x86_64 7
docker-ce-stable 23 M
docker-ce-cli x86_64 1:7
docker-ce-stable 40 M
Transaction Summary
============================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 87 M
Installed size: 363 M
Is this ok [y/d/N]: y
Downloading packages:
warning:
/var/cache/yum/x86_64/7/docker-ce-stable/packages/7.x86_:
Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 1.3 MB/s | 39 MB
00:00:36 ETA
Public key for 7.x86_ is not installed
(1/4): 7.x86_
| 24 MB 00:00:36
warning: /var/cache/yum/x86_64/7/extras/packages/:
Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY ] 1.3 MB/s | 45 MB
00:00:32 ETA
Public key for is not installed
(2/4):
| 39 kB 00:00:41
(3/4): 7.x86_
| 23 MB 00:01:01
(4/4): 7.x86_
| 40 MB 00:00:42
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total
1.1 MB/s | 87 MB 00:01:19
Retrieving key from /docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm)
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : /docker-ce/linux/centos/gpg
Is this ok [y/N]: y
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key)
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : .x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:
1/4
Installing : 7.x86_64
2/4
Installing : 1:7.x86_64
3/4
Installing : 3:7.x86_64
4/4
Verifying : 3:7.x86_64
1/4
Verifying : 1:7.x86_64
2/4
Verifying : 7.x86_64
3/4
Verifying : 2:
4/4
Installed:
docker-ce.x86_64 3:7
Dependency Installed:
2:7 .x86_64
0:7 docker-ce-cli.x86_64 1:7
Complete!
安装成功,启动docker进程:
[root@bogon ~]#
[root@bogon ~]# systemctl start docker
[root@bogon ~]# systemctl enable docker
Created symlink from /etc/systemd/system//e
/usr/lib/systemd/system/e.
[root@bogon ~]#
to
查看docker状态
[root@bogon ~]# systemctl status docker
● e - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/e; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-02-21 19:42:29 PST; 22s ago
Docs:
Main PID: 10553 (dockerd)
CGroup: //e
└─10553 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/
Feb 21 19:42:27 docker dockerd[10553]: time="2020-02-21T19:42:27.535045863-08:00"
level=info msg="scheme "unix" not registered, fallback to default scheme" module=grpc
Feb 21 19:42:27 docker dockerd[10553]: time="2020-02-21T19:42:27.535081253-08:00"
level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/
module=grpc
Feb 21 19:42:27 docker dockerd[10553]: time="2020-02-21T19:42:27.535107105-08:00"
level=info msg="ClientConn switching balancer to "pick_first"" module=grpc
Feb 21 19:42:27 docker dockerd[10553]: time="2020-02-21T19:42:27.635007791-08:00"
level=info msg="Loading containers: start."
Feb 21 19:42:28 docker dockerd[10553]: time="2020-02-21T19:42:28.354209593-08:00"
level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16.
IP address"
Feb 21 19:42:29 docker dockerd[10553]: time="2020-02-21T19:42:29.097833464-08:00"
level=info msg="Loading containers: done."
Feb 21 19:42:29 docker dockerd[10553]: time="2020-02-21T19:42:29.182055014-08:00"
level=info msg="Docker daemon" commit=369ce74a3c graphdriver(s)=overlay2 version=19.03.6
Feb 21 19:42:29 docker dockerd[10553]: time="2020-02-21T19:42:29.182193961-08:00"
level=info msg="Daemon has completed initialization"
Feb 21 19:42:29 docker systemd[1]: Started Docker Application Container Engine.
Feb 21 19:42:29 docker dockerd[10553]: time="2020-02-21T19:42:29.258868440-08:00"
level=info msg="API listen on /var/run/"
Hint: Some lines were ellipsized, use -l to show in full.
[root@bogon ~]#
创建名为konggu的容器,并使用httpd的镜像源:
[root@bogon ~]# docker create --name konggu httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
bc51dd8edc1b: Pull complete
dca5bc65e18f: Pull complete
ccac3445152a: Pull complete
8515f2015fbc: Pull complete
e35494488b8c: Pull complete
Digest: sha256:b783a610e75380aa152dd855a18368ea2f3becb5129d0541e2ec8b662cbd8afb
Status: Downloaded newer image for httpd:latest
7a694fe59d001ea5b132de17e8bf3e0a1400853acab2a16b1da2507a3ceb3aa4
查看容器状态
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7a694fe59d00 httpd "httpd-foreground" 48 seconds ago
Created konggu
启动容器:
[root@bogon ~]# docker start konggu
konggu
再次查看状态
[root@bogon ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7a694fe59d00 httpd "httpd-foreground" About a minute ago
Up 2 seconds 80/tcp konggu
[root@bogon ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7a694fe59d00 httpd "httpd-foreground" 2 minutes ago Up
49 seconds 80/tcp konggu
进入容器:
[root@bogon ~]# docker exec -it konggu bash
root@7a694fe59d00:/usr/local/apache2#
root@7a694fe59d00:/usr/local/apache2#
root@7a694fe59d00:/usr/local/apache2#
root@7a694fe59d00:/usr/local/apache2# ls
bin build cgi-bin conf error htdocs icons include logs modules
[root@bogon ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
7a694fe59d00 httpd "httpd-foreground" 7 minutes ago Up
5 minutes 80/tcp konggu
删除容器
[root@bogon ~]# docker stop konggu
konggu
[root@bogon ~]# docker rm konggu
konggu
[root@bogon ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
重新创建带端口号的容器
[root@bogon ~]# docker run --name konggu -d -p 8080:80 httpd
19f0c0b40353114a639fd02f3d808f8b142c714ccec24f9cf14f5cb66af02409
[root@bogon ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
19f0c0b40353 httpd "httpd-foreground" 12 seconds ago Up
10 seconds 0.0.0.0:8080->80/tcp konggu
[root@bogon ~]# docker exec -it konggu bash
root@19f0c0b40353:/usr/local/apache2#
root@19f0c0b40353:/usr/local/apache2# cd htdocs/
root@19f0c0b40353:/usr/local/apache2/htdocs# ls
root@19f0c0b40353:/usr/local/apache2/htdocs# echo "konggu" >
root@19f0c0b40353:/usr/local/apache2/htdocs#
成功修改了web内容,实验成功。
版权声明:本文标题:docker基础安装使用 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1704430712h459559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论