工做緣由須要在客戶現場離線安裝docker,網上看了不少,官方文檔也查了一下,總結以下:linux
(已在客戶現場成功安裝,Centos7,其餘linux版本沒試過,感受應該問題不大)docker
1. 下載離線安裝包bash
提早找一臺能上網的機器下載好離線安裝包服務器
地址:https://download.docker.com/linux/static/stable/app
選擇合適本身的版本。我這裏用的是x86-64/docker-18.03.1-ce.tgzui
2. 安裝this
安裝包上傳至服務器,解壓縮:spa
tar -zxvf docker-18.03.1-ce.tgz
解壓縮後的文件拷貝到對應目錄:rest
cp docker/* /usr/bin/
3.註冊docker服務日誌
新建一個文件vi docker.service 內容以下:
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
將docker.service 拷貝到對應目錄下:
cp docker.service /usr/lib/systemd/system/
4.啓動和驗證
啓動docker服務:
systemctl start docker
驗證是否成功:
##這裏就比較隨意,用一些經常使用的docker命令 docker -v docker --help
5. docker 經常使用命令
# 查看docker 鏡像 docker images # 查看docker全部容器 docker ps -a # 運行中的容器 docker ps # 運行一個新容器 docker run # 啓動|中止|重啓 已經存在的容器 docker start|stop|restart # 導出鏡像 docker save –o myapp.tar imageName (–o輸出到文件) # 導入鏡像 docker load –i myapp.tar # 刪除鏡像 docker rmi [鏡像名稱或ID] # 刪除容器 docker rm [容器名稱] # 進入容器 docker exec –it [容器名稱] /bin/bash # 查看容器日誌 docker logs –f [容器名稱]