Docker指令說明
本文指令不全,如果你想看全部指令 docker --help
某條指令具體使用方法 docker command --help
不止是Docker其他軟件你都可以用這種方法去查看指令以及介紹
安裝
- 移除老版本
apt-get remove docker docker-engine
apt-get remove lxc-docker
```
2.執(zhí)行以下指令安裝可以讓apt使用基于HTTPS的倉庫
```
apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
```
3.添加Docker的官方GPG密鑰
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
2.添加docker到apt安裝源
```
sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
apt-get update
```
驗證指紋是否正確:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
```
apt-key fingerprint 0EBFCD88
```
4.使用以下命令設置穩(wěn)定版本庫
```
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
```
5.apt-get 更新一下
```
apt-get update
```
6.安裝
```
apt-get install docker-ce
```
- 在生產(chǎn)系統(tǒng)上回溺,您應該安裝特定版本的Docker混萝,而不是始終使用最新版本萍恕。
```
apt-get install docker-ce=
```
7.驗證
```
docker run hello-world
```
##### 使用
- 獲取鏡像:docker pull ubuntu:16.10
root@ubuntu:~/docker# docker pull ubuntu:16.10
16.10: Pulling from library/ubuntu
869d7e479fb8: Already exists
fcde8cc75da4: Pull complete
b9d18efd03be: Pull complete
95ed9114795e: Pull complete
63ec97b2b19c: Pull complete
Digest: sha256:2c935ced8a4ebecab443216ee4dd9e11dc1c85f81a04f07277f99567238f00d9
Status: Downloaded newer image for ubuntu:16.10
- 查看鏡像:docker images
root@ubuntu:~/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16.10 8d4c9ae219d0 11 days ago 106 MB
hello-world latest 48b5124b2768 4 months ago 1.84 kB
```
- 創(chuàng)建新容器:docker create -it ubuntu /bin/bash
r oot@ubuntu:~/docker# docker create -it ubuntu:16.10
7152c34497553e4ab32f844b20a02e61c3a956e960ab9a19ad46f34603c4ef60(返回的ID)
- 創(chuàng)建并運行一個新容器:docker run -it ubuntu /bin/bash
root@ubuntu:~/docker# docker run -it ubuntu:16.10
root@e3a8388cadb9:/#
- 查看所有容器:docker ps -a
- 啟動一個容器:docker start [id_prefix]
- 停止一個容器:docker stop [id_prefix]
- 進入一個容器:docker attach [id_prefix]
- 退出容器并關(guān)閉:ctrl+d(快捷鍵)
- 只退出不關(guān)閉:ctrl+p+q(快捷鍵)
- 在一個運行的容器中執(zhí)行指令:docker exec -ti [id_prefix] /bin/bash
- 從容器中創(chuàng)建一個images鏡像:docker commit -a [author] -m [message] [container_id_prefix] [repository]:[Tag]
- 查看images:docker images
- 導出一個容器到tar文件:docker export -o [file] [id_prefix]
- 從容器文件中導入一個images:docker import -m [message] [file] [repository]:[Tag]
- 導出image鏡像到tar文件:docker save -o [file] [repository]:[tag]或ImageID
- 導入image鏡像從tar文件:docker load -i [file]
##### [Docker遠程倉庫](https://hub.docker.com)
1. 在[docker倉庫](https://hub.docker.com)創(chuàng)建賬戶
2. 本地登陸:docker -u [username] -p [passwrd]
3. 將image鏡像打成你的(REPOSITORY:TAG):docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
4. push到遠程倉庫:docker push [NAME]:[TAG]