本文介紹 Docker CE 簡單的安裝。
先附上我的安裝環(huán)境:VMware14+centos7
1.移除舊的版本(如果之前沒有安裝過,可以跳過這步):
yum remove docker \
? ? ? ? ? ? ? ? ? docker-client \
? ? ? ? ? ? ? ? ? docker-client-latest \
? ? ? ? ? ? ? ? ? docker-common \
? ? ? ? ? ? ? ? ? docker-latest \
? ? ? ? ? ? ? ? ? docker-latest-logrotate \
? ? ? ? ? ? ? ? ? docker-logrotate \
? ? ? ? ? ? ? ? ? docker-selinux \
? ? ? ? ? ? ? ? ? docker-engine-selinux \
? ? ? ? ? ? ? ? ? docker-engine
2.安裝一些必要的系統(tǒng)工具:
yum install -y yum-utils device-mapper-persistent-data lvm2
3.添加軟件源信息:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.更新 yum 緩存:
yum makecache fast
5.安裝Docker-ce:
yum -y install docker-ce
6.啟動Docker后臺服務(wù):
systemctl start docker
7.測試運(yùn)行hello-world
docker run hello-world
執(zhí)行之后如果出現(xiàn)下面的提示就成功了:
[root@localhost ~]# 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/
[root@localhost ~]#
下面附上一些常用的Docker命令(下列ID均為CONTAINER ID字段的值,可用Docker ps -a查看):
docker images? ? ? 查看鏡像
docker pull centos:7.5.1804? 拉取鏡像
docker? rmi? 【-f? 強(qiáng)制刪除】? 鏡像名字:版本? 或者鏡像ID
docker save -o my_centos_7.5.1804.tar centos:7.5.1804? ? ? ? 將鏡像保存到哪個文件
docker load --input my_centos_7.5.1804? ? ? 加載鏡像
docker ps? ? 查詢所有運(yùn)行的容器
docker ps? -a? 查詢所有的容器
docker? exec? -it[開啟一個偽終端]? ID? /bin/bash? 進(jìn)入容器
yum install -y net-tools? 安裝網(wǎng)絡(luò)工具,比如可以執(zhí)行ifconfig
docker? create? -it? centos:7.5.1804? 創(chuàng)建容器,跟run區(qū)別主要在exit
docker? run? ? -it? centos:7.5.1804? 創(chuàng)建并運(yùn)行容器,跟create區(qū)別主要在exit
docker? start? ID? 啟動容器
docker? rm? ID? 刪除容器
docker? stop ID? 停止容器
exit? 退出容器(如果是create容器并啟動,退出之后可以查看得到正在運(yùn)行的容器,如果是run則會一并退出,查看不到正在運(yùn)行的容器)
刪除 Docker CE,執(zhí)行以下命令來刪除 Docker CE:
yum remove docker-ce
rm -rf /var/lib/docker
鏡像可以去官網(wǎng)上查找:?https://www.docker.com/