1. 修改位置

查看我们挂载的磁盘

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.7M  1.6G   1% /run
/dev/sda2       110G   18G   86G  18% /
tmpfs           7.8G  152M  7.7G   2% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sdb1       916G   77M  870G   1% /data
/dev/sda1       511M  6.1M  505M   2% /boot/efi
tmpfs           1.6G   16K  1.6G   1% /run/user/121
tmpfs           1.6G   28K  1.6G   1% /run/user/1000
tmpfs           1.6G     0  1.6G   0% /run/user/0

选择 /data作为docker容器存放地址。

docker info #查看docker的基本信息

停止docker服务

systemctl stop docker / 或可在openwrt的启动项中直接停止服务

备份原目录

cp -r /var/lib/docker  /data/docker
mv /var/lib/docker /var/lib/docker.bak
ln -s /data/docker /var/lib/docker
systemctl start docker

运行Hello world

# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

查看docker info

# docker info
Containers: 3
 Running: 0
 Paused: 0
 Stopped: 3
Images: 1
Server Version: 18.09.7
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.18.0-20-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.54GiB
Name: ryan-computer
ID: P5ON:MZEK:XB4K:63NP:DTUX:BQHY:72AR:OP4G:JQ2M:JNDL:T6TU:6NEJ
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

WARNING: No swap limit support

成功运行Hello World后再修改配置文件

最简单粗暴的办法,当然就是直接把数据盘挂载到/var/lib/docker 目录下,不过这样对整体影响太大,其他程序需要使用数据盘时很不方便,所以还是从 Docker 端的修改入手。

官方文档的修改办法是编辑 /etc/docker/daemon.json 文件:

vi /etc/docker/daemon.json 

默认情况下这个配置文件是没有的,这里实际也就是新建一个,然后写入以下内容:

{
  "data-root": "/www/docker"
}

此文件还涉及默认源的设定,如果设定了国内源,那么实际就是在源地址下方加一行,写成:

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"],
  "data-root": "/www/docker"
}

最后重启服务即可。

参考
https://www.cnblogs.com/woshimrf/p/after-install-docker.html
https://zhuanlan.zhihu.com/p/95533274

标签: none

添加新评论