Docker 實戰
一、基本部署
此篇爲老版本的部署安裝,新版 CE 安裝請移步:Dcker CE 部署安裝
1. Docker 官網
在官網可以找到關於docker的任何你想要的信息。
2. Centos 7 部署 docker
2.1首先確認系統處於最新狀態
$ sudo yum update
2.2 添加Docker 的YUM源
$ sudo tee /etc/yum.repos.d/docker.repo <<- EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
2.3 開始安裝Docker 引擎
$ sudo yum -y install docker-engine
2.4 設置開機啓動 dokcer daemon 進程
$ sudo systemctl enable docker.service
2.5 啓動 Docker daemon
$ sudo systemctl start docker
2.6 查看狀態
$ sudo systemctl status docker.server
2.7 驗證Docker
$ sudo docker run --rm hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world
c04b14da8d14: Pull complete
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
..............略...............
#注:當你看到以上信息,表示docker已經成功安裝且運行正常。
#注: 禁用 firewalld
$ systemctl disable firewalld
$ yum -y install iptables-services
$ systemctl enables iptables
$ systemctl start iptables
3. 簡單操作
3.1查看安裝後的Dockers信息
以下是我直接用root 用戶操作的,當然你也可以用 sudo方式。
查看docker相關信息
[root@x201t ~]# docker info
查看docker版本信息
[root@x201t ~]#docker version
[root@x201t ~]#docker -v
查看docker的虛擬網絡(網橋)
[root@x201t ~]# ip a
3.2 Docker 的配置文件
配置文件用於對docker daemon啓動時對docker進行一些全局性的配置,其中包
括環境變量、鏡像倉庫地址等。
[root@x201t ~]# cat /etc/default/docker
DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io"
# --registry-mirror 表示在互聯網上Docker Registry的鏡像地址
3.3 獲取命令幫助
在命令行中直接輸入docker 回車,會看的關於docker支持的所有命令和一些通用
參數的幫助信息
[root@x201t ~]# docker
Usage: docker [OPTIONS] COMMAND [arg...]
docker [ --help | -v | --version ]
A self-sufficient runtime for containers.
.........................
若想進一步獲取docker 子命令的參數和用法的幫助信息,可以輸入
docker + 子命令 --help
如:
[root@x201t ~]# docker start --help
當你是用rpm包安裝的docker時,也可以用man來獲取更爲詳盡的幫助信息
[root@x201t ~]# man docker
[root@x201t ~]# man docker start