Docker【安装与基本使用】

这篇具有很好参考价值的文章主要介绍了Docker【安装与基本使用】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【1】Docker的安装

注意:如果之前安装过docker其他版本,请删除干净。

docker-01

10.0.0.51

2G

docker-02

10.0.0.52

2G

 docker-01

[root@docker-01 ~]# cp -rp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
cp: overwrite ‘/etc/localtime’? y

[root@docker-01 ~]# ntpdate ntp1.aliyun.com

[root@docker-01 ~]# hwclock --systohc

[root@docker-01 ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

Docker【安装与基本使用】,Docker,docker,spring cloud,容器

[root@docker-01 ~]#  wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
--2023-07-17 21:26:12--  http://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1919 (1.9K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’

100%[=========================================================>] 1,919       --.-K/s   in 0s      

2023-07-17 21:26:12 (10.2 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved [1919/1919]

[root@docker-01 ~]# sed -i 's+donload.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

[root@docker-01 ~]# yum -y install docker-ce

[root@docker-01 ~]# mkdir docker-ce
[root@docker-01 ~]# find /var/cache/yum/x86_64/7/ -type f -name "*.rpm" | xargs mv -t docker-ce/

[root@docker-01 ~]# docker version 
Client: Docker Engine - Community
 Version:           24.0.4
 API version:       1.43
 Go version:        go1.20.5
 Git commit:        3713ee1
 Built:             Fri Jul  7 14:54:21 2023
 OS/Arch:           linux/amd64
 Context:           default
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

[root@docker-01 ~]# systemctl start docker
[root@docker-01 ~]# systemctl enable docker

[root@docker-01 ~]# tar -zcvf docker-ce.tar.gz docker-ce/
[root@docker-01 ~]# scp -rp docker-ce.tar.gz root@10.0.0.52:/root
The authenticity of host '10.0.0.52 (10.0.0.52)' can't be established.
ECDSA key fingerprint is 91:14:1f:5c:f9:69:6e:12:5f:fa:dd:61:bc:ef:3e:68.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.52' (ECDSA) to the list of known hosts.
root@10.0.0.52's password: 
docker-ce.tar.gz                                                 100%  116MB 116.5MB/s   00:01   

 docker-02

[root@docker-02 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   6100      0 --:--:-- --:--:-- --:--:--  6108

[root@docker-02 ~]# tar xf docker-ce.tar.gz 
[root@docker-02 ~]# cd docker-ce/
[root@docker-02 docker-ce]# yum localinstall -y *.rpm

[root@docker-02 docker-ce]# systemctl start docker
[root@docker-02 docker-ce]# systemctl enable docker

[root@docker-02 docker-ce]# docker version 
Client: Docker Engine - Community
 Version:           24.0.4
 API version:       1.43
 Go version:        go1.20.5
 Git commit:        3713ee1
 Built:             Fri Jul  7 14:54:21 2023
 OS/Arch:           linux/amd64
 Context:           default

【2】docker常用命令 

搜索镜像 - search

[root@docker-01 ~]# docker search nginx
NAME                                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                        18762     [OK]       
unit                                              Official build of NGINX Unit: Universal Web …   6         [OK]       

下载镜像 - pull

[root@docker-01 ~]# docker pull nginx:latest
latest: Pulling from library/nginx
faef57eae888: Pull complete 
76579e9ed380: Pull complete 
cf707e233955: Pull complete 
91bb7937700d: Pull complete 
4b962717ba55: Pull complete 
f46d7b05649a: Pull complete 
103501419a0a: Pull complete 
Digest: sha256:08bc36ad52474e528cc1ea3426b5e3f4bad8a130318e3140d6cfe29c8892c7ef
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

 查看存在的镜像 - image ls

[root@docker-01 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    021283c8eb95   12 days ago   187MB

## 或使用 images
[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    021283c8eb95   12 days ago   187MB

 删除镜像 - image rm

[root@docker-01 ~]# docker image rm nginx:latest 
Untagged: nginx:latest
Untagged: nginx@sha256:08bc36ad52474e528cc1ea3426b5e3f4bad8a130318e3140d6cfe29c8892c7ef
Deleted: sha256:021283c8eb95be02b23db0de7f609d603553c6714785e7a673c6594a624ffbda
Deleted: sha256:a9de33035096cdf7bbaf7f3e1291701c0620d2a0e66152228abef35a79002876
Deleted: sha256:d66c35807d98c6f37bd2a14c6506a42d27a40fbdb564e233f7a78aafdc636c59
Deleted: sha256:a4c423818ed6dc12a545c349d0dc36a5695446448e07229e96c7235a126c2520
Deleted: sha256:c04094edc9df98c870e281f3b947a7782ca6d542d8715814ac06786466af3659
Deleted: sha256:c9c467815e8fe87d99f0f500495cf7f4f9096cf6c116ef2782e84bb17a4a5e06
Deleted: sha256:4645f26713fbea51190f5de52b88fbe27b42efd61c0dba87c81fa16df9a8f649
Deleted: sha256:24839d45ca455f36659219281e0f2304520b92347eb536ad5cc7b4dbb8163588

[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

## 或使用 rmi
[root@docker-01 ~]# docker pull nginx:latest
[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    021283c8eb95   12 days ago   187MB
[root@docker-01 ~]# docker rmi nginx:latest 
Untagged: nginx:latest
Untagged: nginx@sha256:08bc36ad52474e528cc1ea3426b5e3f4bad8a130318e3140d6cfe29c8892c7ef
Deleted: sha256:021283c8eb95be02b23db0de7f609d603553c6714785e7a673c6594a624ffbda
Deleted: sha256:a9de33035096cdf7bbaf7f3e1291701c0620d2a0e66152228abef35a79002876
Deleted: sha256:d66c35807d98c6f37bd2a14c6506a42d27a40fbdb564e233f7a78aafdc636c59
Deleted: sha256:a4c423818ed6dc12a545c349d0dc36a5695446448e07229e96c7235a126c2520
Deleted: sha256:c04094edc9df98c870e281f3b947a7782ca6d542d8715814ac06786466af3659
Deleted: sha256:c9c467815e8fe87d99f0f500495cf7f4f9096cf6c116ef2782e84bb17a4a5e06
Deleted: sha256:4645f26713fbea51190f5de52b88fbe27b42efd61c0dba87c81fa16df9a8f649
Deleted: sha256:24839d45ca455f36659219281e0f2304520b92347eb536ad5cc7b4dbb8163588
[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

 导出镜像 - save

[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    021283c8eb95   12 days ago   187MB
alpine       latest    c1aabb73d233   4 weeks ago   7.33MB
[root@docker-01 ~]# docker save nginx:latest -o docker_nginx_latest.tar.gz
[root@docker-01 ~]# ls
anaconda-ks.cfg  docker_nginx_latest.tar.gz

 将多个镜像导出到同一个tar包

[root@docker-01 ~]# docker save -o docker_nginx_latest_alpine_laster.tar.gz nginx:latest alpine:latest 
[root@docker-01 ~]# ls
anaconda-ks.cfg  docker_nginx_latest_alpine_laster.tar.gz

 导入镜像 - load文章来源地址https://www.toymoban.com/news/detail-596849.html

[root@docker-01 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@docker-01 ~]# docker load -i docker_nginx_latest.tar.gz 
24839d45ca45: Loading layer [==================================================>]  77.81MB/77.81MB
b821d93f6666: Loading layer [==================================================>]  113.2MB/113.2MB
1998c5cd2230: Loading layer [=============

到了这里,关于Docker【安装与基本使用】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包