Docker 學習之 安裝與卸載docker鏡像


一,安裝Docker-CE

本文采用阿里雲提供的鏡像站來安裝

1,安裝所需工具

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

2,添加yum源

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

將下載到本地 /etc/yum.repos.d/ 下

3,更新並安裝

[root@localhost ~]# yum makecache fast

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

4,啟動docker服務

[root@localhost ~]# systemctl start docker

  檢查是否正常安裝:

  yum list installed | grep docker

  docker info

5,安裝指定版本的docker-ce:

查看版本:

[root@localhost ~]# yum list docker-ce.x86_64 --showduplicates | sort -r

* updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
* extras: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos @docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.tuna.tsinghua.edu.cn
Available Packages

安裝指定版本

[root@localhost ~]# yum -y install docker-ce-17.12.0.ce-1.el7.centos
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Package docker-ce-17.12.0.ce-1.el7.centos.x86_64 already installed and latest version
Nothing to do

6,查看安裝docker信息

[root@localhost ~]# docker version
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:10:14 2017
OS/Arch: linux/amd64

Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:12:46 2017
OS/Arch: linux/amd64
Experimental: false

7,測試docker

[root@localhost ~]#docker run hello-world

8,查看是否運行:

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 3 months ago 1.85kB

9,運行一個httpd鏡像:

[root@localhost ~]# docker run -d -p 8088:80 httpd

Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
4176fe04cefe: Downloading [=================> ] 18.73MB/52.61MB
d6c01cf91b98: Download complete
b7066921647a: Download complete

......

從 Docker Hub 下載 httpd 鏡像。鏡像中已經安裝好了 Apache HTTP Server,並將容器的 80 端口映射到 host 的 8088 端口

然后訪問:http://[hostIP:8088]就可以看到效果了

 

 

二,如何卸載Docker-CE

1,查看是否已經安裝的Docker軟件包

yum list installed | grep docker

2,如果已安裝不想要docker、docker-engine、docker-ce相關的軟件包,則卸載掉

yum -y remove docker docker-common docker-selinux docker-engine docker-engine-selinux container-selinux docker-ce

3,刪除所有的鏡像、容器、數據卷、配置文件等

rm -rf /var/lib/docker

 

三,補充

解決國內獲取docker鏡像緩慢問題

一,中國科技大學開源鏡像站:https://docker.mirrors.ustc.edu.cn

{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]}

二,daemon.json 一些配置

{ //配置倉庫鏡像地址 "registry-mirrors": ["https://kzflb.mirror.aliyuncs.com"], //默認http私有倉庫不能訪問,設置后才可以 "insecure-registries": ["http://192.168.200.10"], //開啟docker-API遠程訪問 "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"] }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM