linux 安裝:
which wget
sudo apt-get install wget
wget -qO- https://get.Docker.com |shnode
Ubuntu 18.04 安裝 Docker-celinux
1.更換國內軟件源,推薦中國科技大學的源,穩定速度快(可選)docker
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn' /etc/apt/sources.list
sudo apt update
2.安裝須要的包ubuntu
sudo apt install apt-transport-https ca-certificates software-properties-common curl
3.添加 GPG 密鑰,並添加 Docker-ce 軟件源,這裏仍是以中國科技大學的 Docker-ce 源爲例api
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
4.添加成功後更新軟件包緩存緩存
sudo apt update
5.安裝 Docker-cebash
sudo apt install docker-ce
6.設置開機自啓動並啓動 Docker-ce(安裝成功後默認已設置並啓動,可忽略)服務器
sudo systemctl enable docker
sudo systemctl start docker
7.測試運行網絡
sudo docker run hello-world
8.添加當前用戶到 docker 用戶組,能夠不用 sudo 運行 docker(可選)app
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
newgrp - docker
sudo usermod -aG docker $USER
9.測試添加用戶組(可選)
docker run hello-world
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default
"/home/lavender/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level
("debug"|"info"|"warn"|"error"|"fatal")
(default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default
"/home/lavender/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default
"/home/lavender/.docker/cert.pem")
--tlskey string Path to TLS key file (default
"/home/lavender/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
deploy Deploy a new stack or update an existing stack
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version
wait Block until one or more containers stop, then print their exit codes
docker
參數詳解
-D 默認false 容許調試模式(debugmode)
-H 默認是unix:///var/run/docker.sock tcp://[host[:port]]來綁定 或者unix://[/path/to/socket]來使用(二進制文件的時候),當主機ip host=[0.0.0.0],(端口)port=[4243] 或者 path=[/var/run/docker.sock]是缺省值,作爲默認值來使用
-api-enable-cors 默認flase 容許CORS header遠程api
-b 默認是空,附加在已存在的網橋上,若是是用'none'參數,就禁用了容器的網絡
-bip 默認是空,使用提供的CIDR(ClasslessInter-Domain Routing-無類型域間選路)標記地址動態建立網橋(dcoker0),和-b參數衝突
-d 默認false 容許進程模式(daemonmode)
-dns 默認是空,使docker使用指定的DNS服務器
-g 默認是"/var/lib/docker":做爲docker使用的根路徑
-icc 默認true,容許inter-container來通訊
-ip 默認"0.0.0.0":綁定容器端口的默認Ip地址
-iptables 默認true 禁用docker添加iptables規則
-mtu 默認1500 : 設置容器網絡傳輸的最大單元(mtu)
-p 默認是/var/run/docker.pid進程pid使用的文件路徑
-r 默認是true 重啓以前運行的容器
-s 默認是空 ,這個是docker運行是使用一個指定的存儲驅動器
-v 默認false 打印版本信息和退出
docker build [OPTIONS] PATH | URL | -
參數說明:
–build-arg=[] :設置鏡像建立時的變量;
–cpu-shares :設置 cpu 使用權重;
–cpu-period :限制 CPU CFS週期;
–cpu-quota :限制 CPU CFS配額;
–cpuset-cpus :指定使用的CPU id;
–cpuset-mems :指定使用的內存 id;
–disable-content-trust :忽略校驗,默認開啓;
-f :指定要使用的Dockerfile路徑;
–force-rm :設置鏡像過程當中刪除中間容器;
–isolation :使用容器隔離技術;
–label=[] :設置鏡像使用的元數據;
-m :設置內存最大值;
–memory-swap :設置Swap的最大值爲內存+swap,」-1″表示不限swap;
–no-cache :建立鏡像的過程不使用緩存;
–pull :嘗試去更新鏡像的新版本;
-q :安靜模式,成功後只輸出鏡像ID;
–rm :設置鏡像成功後刪除中間容器;
–shm-size :設置/dev/shm的大小,默認值是64M;
–ulimit :Ulimit配置。
docker commit :從容器建立一個新的鏡像。
參數說明:
-a :提交的鏡像做者;
-c :使用Dockerfile指令來建立鏡像;
-m :提交時的說明文字;
-p :在commit時,將容器暫停。
docker events : 從服務器獲取實時事件
參數說明:
-f :根據條件過濾事件;
--since :從指定的時間戳後顯示全部事件;
--until :流水時間顯示到指定的時間爲止;
docker exec :在運行的容器中執行命令
參數說明:
-d :分離模式: 在後臺運行
-i :即便沒有附加也保持STDIN 打開
-t :分配一個僞終端
docker export :將文件系統做爲一個tar歸檔文件導出到STDOUT。
參數說明:
-o :將輸入內容寫到文件。
docker history : 查看指定鏡像的建立歷史。
參數說明:
-H :以可讀的格式打印鏡像大小和日期,默認爲true; --no-trunc :顯示完整的提交記錄; -q :僅列出提交記錄ID。
docker images : 列出本地鏡像。
參數說明:
-a :列出本地全部的鏡像(含中間映像層,默認狀況下,過濾掉中間映像層);
--digests :顯示鏡像的摘要信息;
-f :顯示知足條件的鏡像;
--format :指定返回值的模板文件;
--no-trunc :顯示完整的鏡像信息;
-q :只顯示鏡像ID。
docker import : 從歸檔文件中建立鏡像。
參數說明:
-c :應用docker 指令建立鏡像;
-m :提交時的說明文字;
docker inspect : 獲取容器/鏡像的元數據。
參數說明:
-f :指定返回值的模板文件。
-s :顯示總的文件大小。
--type :爲指定類型返回JSON。
docker kill :殺掉一個運行中的容器。
參數說明:
-s :向容器發送一個信號
docker login : 登錄到一個Docker鏡像倉庫,若是未指定鏡像倉庫地址,默認爲官方倉庫 Docker Hub
參數說明:
-u :登錄的用戶名
-p :登錄的密碼
docker logs : 獲取容器的日誌
參數說明:
-f : 跟蹤日誌輸出
--since :顯示某個開始時間的全部日誌
-t : 顯示時間戳
--tail :僅列出最新N條容器日誌
docker ps : 列出容器
參數說明:
-a :顯示全部的容器,包括未運行的。
-f :根據條件過濾顯示的內容。
--format :指定返回值的模板文件。
-l :顯示最近建立的容器。
-n :列出最近建立的n個容器。
--no-trunc :不截斷輸出。
-q :靜默模式,只顯示容器編號。
-s :顯示總的文件大小。
docker pull : 從鏡像倉庫中拉取或者更新指定鏡像
參數說明:
-a :拉取全部 tagged 鏡像
docker rm :刪除一個或多少容器
參數說明:
-f :經過SIGKILL信號強制刪除一個運行中的容器
-l :移除容器間的網絡鏈接,而非容器自己
-v :-v 刪除與容器關聯的卷
docker rmi : 刪除本地一個或多少鏡像。
參數說明:
-f :強制刪除;
--no-prune :不移除該鏡像的過程鏡像,默認移除;
docker run :建立一個新的容器並運行一個命令
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
-a, --attach=[] 登陸容器(以docker run -d啓動的容器)
-c, --cpu-shares=0 設置容器CPU權重,在CPU共享場景使用
--cap-add=[] 添加權限,權限清單詳見:http://linux.die.net/man/7/capabilities
--cap-drop=[] 刪除權限,權限清單詳見:http://linux.die.net/man/7/capabilities
--cidfile="" 運行容器後,在指定文件中寫入容器PID值,一種典型的監控系統用法
--cpuset="" 設置容器可使用哪些CPU,此參數能夠用來容器獨佔CPU
-d, --detach=false 指定容器運行於前臺仍是後臺
--device=[] 添加主機設備給容器,至關於設備直通
--dns=[] 指定容器的dns服務器
--dns-search=[] 指定容器的dns搜索域名,寫入到容器的/etc/resolv.conf文件
-e, --env=[] 指定環境變量,容器中可使用該環境變量
--entrypoint="" 覆蓋image的入口點
--env-file=[] 指定環境變量文件,文件格式爲每行一個環境變量
--expose=[] 指定容器暴露的端口,即修改鏡像的暴露端口
-h, --hostname="" 指定容器的主機名
-i, --interactive=false 打開STDIN,用於控制檯交互
--link=[] 指定容器間的關聯,使用其餘容器的IP、env等信息
--lxc-conf=[] 指定容器的配置文件,只有在指定--exec-driver=lxc時使用
-m, --memory="" 指定容器的內存上限
--name="" 指定容器名字,後續能夠經過名字進行容器管理,links特性須要使用名字
--net="bridge" 容器網絡設置,待詳述
-P, --publish-all=false 指定容器暴露的端口,待詳述
-p, --publish=[] 指定容器暴露的端口,待詳述
--privileged=false 指定容器是否爲特權容器,特權容器擁有全部的capabilities
--restart="" 指定容器中止後的重啓策略,待詳述
--rm=false 指定容器中止後自動刪除容器(不支持以docker run -d啓動的容器)
--sig-proxy=true 設置由代理接受並處理信號,可是SIGCHLD、SIGSTOP和SIGKILL不能被代理
-t, --tty=false 分配tty設備,該能夠支持終端登陸
-u, --user="" 指定容器的用戶
-v, --volume=[] 給容器掛載存儲卷,掛載到容器的某個目錄
--volumes-from=[] 給容器掛載其餘容器上的卷,掛載到容器的某個目錄
-w, --workdir="" 指定容器的工做目錄
docker search : 從Docker Hub查找鏡像
參數說明:
--automated :只列出 automated build類型的鏡像;
--no-trunc :顯示完整的鏡像描述;
-s :列出收藏數不小於指定值的鏡像。
鏡像使用:
建立鏡像:
1.從已經建立的容器中更新鏡像,而且提交這個鏡像
runoob@runoob:~$ docker run -t -i ubuntu:15.10 /bin/bash
root@e218edb10161:/# 在運行的容器內使用 apt-get update 命令進行更新。
在完成操做以後,輸入 exit命令來退出這個容器。
此時ID爲e218edb10161的容器,是按咱們的需求更改的容器。咱們能夠經過命令 docker commit來提交容器副本。 runoob@runoob:~$ docker commit -m="has update" -a="runoob" e218edb10161 runoob/ubuntu:v2 sha256:70bf1840fd7c0d2d8ef0a42a817eb29f854c1af8f7c59fc03ac7bdee9545aff8 各個參數說明: -m:提交的描述信息 -a:指定鏡像做者 e218edb10161:容器ID runoob/ubuntu:v2:指定要建立的目標鏡像名 2.使用 Dockerfile 指令來建立一個新的鏡像