当前位置:   article > 正文

Ubuntu 离线安装docker_ubuntu16.04离线安装docker

ubuntu16.04离线安装docker

Ubuntu 离线安装docker、修改docker存储路径、日志删除

如果你无法使用Docker’s apt repository 安装 Docker Engine,你可以下载deb文件然后手动安装。

  1. 去 https://download.docker.com/linux/ubuntu/dists/ 下载安装包
  2. 选在ubuntu对应的版本,18.04对应的是bionic
  3. 然年进入pool/stable/,选择架构 (amd64, armhf, arm64, or s390x),x86架构服务器选择amd64
  4. 下载下列安装包,Docker Engine, CLI, containerd, and Docker Compose packages:
    containerd.io_<version>_<arch>.deb
    docker-ce_<version>_<arch>.deb
    docker-ce-cli_<version>_<arch>.deb
    docker-buildx-plugin_<version>_<arch>.deb
    docker-compose-plugin_<version>_<arch>.deb
    
    • 1
    • 2
    • 3
    • 4
    • 5
  5. 安装
    sudo dpkg -i ./containerd.io_1.4.12-1_amd64.deb \ 
              ./docker-ce_20.10.10_3-0_ubuntu-bionic_amd64.deb \
              ./docker-ce-cli_20.10.10_3-0_ubuntu-bionic_amd64.deb \
              ./docker-buildx-plugin_0.10.2-1_ubuntu.18.04_bionic_amd64.deb \
              ./docker-compose-plugin_2.10.2_ubuntu-bionic_amd64.deb
    
    • 1
    • 2
    • 3
    • 4
    • 5

docker daemon会自启动,用docker ps 命令验证

  1. 修改docker镜像等的存储路径
# 先停掉服务
systemctl stop docker
# 备份docker.service
cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service-bak
# 修改/lib/systemd/system/docker.service文件添加如下
ExecStart=/usr/bin/dockerd -g /home/dorahou/docker -H fd:// --containerd=/run/containerd/containerd.sock
# 启动服务
systemctl start docker
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

docker.service参考文件,如果版本与我一致可直接拷贝替换

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -g /home/dorahou/docker -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  1. 修改docker日志存储大小
    有些场景下日志特别大,需要定时删除,可通过修改docker的daemon.json文件实现
# 先停掉服务
systemctl stop docker
# /etc/docker/目录下创建daemon.json文件
touch daemon.json
  • 1
  • 2
  • 3
  • 4

daemon.json文件参考如下:

{
    "registry-mirrors":["https://regustrt,dicjer-cn.com"],
    "dns":["8.8.8.8","114.114.114.114"],
    "log-driver":"json-file",
    "log-opts":{"max-size":"200m","max-file":"3"}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
# 启动服务
systemctl start docker
  • 1
  • 2
  1. docker常用命令
# 查看在运行容器
docker ps
# 查看所有容器
docker ps -a
# 查询容器日志
docker logs {container} --tail 1000
# 启动一个新容器,最后的nginx表示镜像名
docker run -it --name=nginx --net=host -v /home/dorahou/nginx/conf.d:/etc/nginx/conf.d -v /home/dorahou/nginx-logs:/var/log/nginx -v /home/dorahou/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/dorahou/vpc:/home/dorahou/vpc nginx
docker run --name snapshot-offline -it --net=host -v /home/dorahou:/home/dorahou -v /home/dorahou/vpc:/home/dorahou/vpc --entrypoint bash snapshot-server:latest
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

docker官方安装链接

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号