sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88 //安全性校驗
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
apt-cache madison docker-ce
sudo apt-get install docker-ce=
sudo apt-get install docker-ce=17.06.2~ce-0~ubuntu
sudo docker run hello-world
卸載
sudo apt-get purge docker-ce
sudo rm -rf /var/lib/docker
創(chuàng)建docker專屬用戶
sudo groupadd docker
sudo systemctl enable docker
sudo systemctl disable docker
鏡像的使用
docker ps // 顯示狀態(tài)為運行(Up)的容器
docker rm $docker_name
docker stop # 停止容器運行扣汪,發(fā)送信號SIGTERM,例如:docker stop mycon
docker start # 啟動一個停止?fàn)顟B(tài)的容器糖权,例如:docker start mycon
docker restart # 重啟一個容器隘世,例如:docker restart mycon
docker rm # 刪除一個容器禁筏,例如:doecker rm mycon
docker kill # 發(fā)送信號給容器滥朱,默認(rèn)SIGKILL鞍历,例如:docker kill -s KILL mycon (-s表示向容器發(fā)送一個信號)
docker logs -f mycon(查看容器mycon的日志輸出)
docker cp /www/test mycon:/www/ #將主機/www/test目錄拷貝到容器mycon的/www目錄下
docker cp /www/test mycon:/www #將主機/www/test目錄拷貝到容器mycon中乌询,目錄重命名為www
docker cp mycon:/www /tmp/test #將容器mycon中的/www目錄拷貝到主機的/tmp/test目錄中
docker images # 顯示本地所有的鏡像列表
docker import my_ubuntu_v3.tar my/ubuntu:v4 #從鏡像歸檔文件my_ubuntu_v3.tar創(chuàng)建鏡像,命名為my/ubuntu:v4
docker build # 使用Dockerfile創(chuàng)建鏡像(推薦)
docker search # 從registry倉庫搜索鏡像
docker search php:5.6-fpm #從Docker Hub查找鏡像名php5.6-fpm
docker search -s 10 java #從Docker Hub查找所有鏡像名包含java矢赁,并且收藏數(shù)大于10的鏡像
docker pull # 從倉庫下載鏡像到本地
docker pull richarvey/nginx-php-fpm
下載鏡像記錄
root@bluedonchen-PowerEdge-T410:/home/bluedonchen# docker pull richarvey/nginx-php-fpm
Using default tag: latest
latest: Pulling from richarvey/nginx-php-fpm
911c6d0c7995: Pull complete
2527cc05836d: Pull complete
3299172a2d6d: Pull complete
05782106624f: Pull complete
3e3261543ec8: Pull complete
ce1c845d4246: Pull complete
e005e70f55dc: Pull complete
84403a106e16: Pull complete
e4fc13f7949f: Pull complete
2a53e72ea7b9: Pull complete
d791f6b71f27: Pull complete
f6df331656e7: Pull complete
5381ec390ca6: Pull complete
2e9a52704f07: Pull complete
7a8ef513204e: Pull complete
df19144db16b: Pull complete
b832cce98a16: Pull complete
6370d6a48a11: Pull complete
924e29dc442b: Pull complete
2bc9f6bfc6a8: Pull complete
72e2f93784df: Pull complete
cb7fbeead5a1: Pull complete
276d9744a2fb: Pull complete
486d85bb5539: Pull complete
4b2c3b875d6a: Pull complete
347e2742b221: Pull complete
90218f1356c9: Pull complete
451db447c8a9: Pull complete
27f73f3b662a: Pull complete
8fa8d5b5be53: Pull complete
Digest: sha256:5d8b5985af7e11ec08747f25dd8bf7c2f7f0b2c590740a005f326ff5f805c09d
Status: Downloaded newer image for richarvey/nginx-php-fpm:latest
docker info #顯示 Docker 系統(tǒng)信息糯笙,包括鏡像和容器數(shù)。
docker version #顯示 Docker 版本信息撩银。參數(shù)-f :指定返回值的模板文件给涕。
運行鏡像
docker run -t -i bitnami/redis /bin/bash
docker run -it --name bdredis bitnami/redis /bin/bash
#其中,-t 選項讓Docker分配一個偽終端(pseudo-tty)并綁定到容器的標(biāo)準(zhǔn)輸入上额获, -i 則讓容器的標(biāo)準(zhǔn)輸入保持打開够庙。也可以合并起來寫
# 不加-t -i的話,執(zhí)行完就退出容器例如抄邀,下面的命令輸出一個 “Hello World”耘眨,之后終止容器。
# 可以通過添加 -d 參數(shù)來實現(xiàn)境肾。例如下面的命令會在后臺運行容器剔难。
docker attach 63e018246bb8
docker start 63e018246bb8
# 默認(rèn)情況下,如果使用ctrl-d退出container,那么container也會stop,按ctrl-p ctrl-q可以退出到宿主機奥喻,而保持container仍然在運行.然后要進(jìn)入再使用docker attach
#輸入exit或ctrl+d
docker run --name some-redis -d redis
docker run -d --name redis-6379 -p 6379:6379 hakimdstx/nodes-redis:4.0.1
docker run -d --name chen-redis -p 6379:6379 redis
倉庫地址
https://hub.docker.com/
鏡像信息查看
root@bluedonchen-PowerEdge-T410:/home/bluedonchen# docker inspect lnp | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
root@bluedonchen-PowerEdge-T410:/home/bluedonchen# curl -I 172.17.0.2
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Aug 2018 06:49:21 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/7.2.8