meta-visionfive2 上docker的部署和运行¶
本章介绍如何在星光2上进行docker的部署和运行。 具体内容如下:
1.部署docker¶
1.1 网络配置¶
进入uboot,设置网络信息
StarFive # setenv ipaddr 192.168.11.46 StarFive # setenv gatewayip 192.168.11.1 StarFive # setenv dnsip 192.168.11.1 StarFive # saveenv Saving Environment to SPIFlash... Erasing SPI flash...Writing to SPI flash...done OK StarFive # ping 192.168.11.42 ethernet@16030000 Waiting for PHY auto negotiation to complete...... done Using ethernet@16030000 device host 192.168.11.42 is alive StarFive #根据个人需要决定是否配置网络相关信息;本镜像提供配置网络脚本net_config.sh,用于初始配置网络,位于/usr/share/docker/目录下, 脚本需要4个参数(配置的网卡名称,ip地址,网关,dns)
root@StarFive:/usr/share/docker# ./net_config.sh eth0 192.168.11.46 192.168.11.1 192.168.11.1 para:net-name ipaddr gatewayip dnsip,for example:eth0 192.168.11.46 192.168.11.1 Net Config Start... [ 3437.420844] starfive-eth-plat 16030000.ethernet eth0: PHY [stmmac-0:00] driver [YT8531 Gigabit Ethernet] (irq=POLL) [ 3437.433543] starfive-eth-plat 16030000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0 [ 3437.443083] dwmac4: Master AXI performs fixed burst length [ 3437.448692] starfive-eth-plat 16030000.ethernet eth0: No Safety Features support found [ 3437.456723] starfive-eth-plat 16030000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported [ 3437.466675] starfive-eth-plat 16030000.ethernet eth0: configuring for phy/rgmii-id link mode [ 3440.576397] starfive-eth-plat 16030000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx root@StarFive:/usr/share/docker#
- [注]:
1.测试网络使用ping指令时,需要加入-w等控制参数,否则进程可能无法正常退出,如:ping -w3 www.baidu.com 2.使用脚本配置网络后,后续需要修改网络配置时,需要自己手动修改。
1.2 修改系统时间¶
系统启动后为初始时间,可能会影响部分功能使用,可通过指令修改时间。
root@StarFive:~# date -s "2023-03-15 00:00:00" Wed Mar 15 00:00:00 UTC 2023 root@StarFive:~# date Wed Mar 15 00:00:10 UTC 2023
1.4 docker版本信息¶
root@StarFive:/usr/share/docker# docker version DEBU[2023-02-27T13:46:15.561883500Z] Calling HEAD /_ping DEBU[2023-02-27T13:46:15.567636750Z] Calling GET /v1.41/version Client: Version: unknown-version API version: 1.41 Go version: go1.16.2 Git commit: d3c36a2a73 Built: Thu Mar 18 22:37:13 2021 OS/Arch: linux/riscv64 Context: default Experimental: true Server: Engine: Version: dev API version: 1.41 (minimum version 1.12) Go version: go1.16.2 Git commit: 788f2883d2 Built: Thu Mar 18 23:11:36 2021 OS/Arch: linux/riscv64 Experimental: false containerd: Version: v1.5.0-beta.4-20-g969b3d638 GitCommit: 969b3d638bbf5fe0296f7b80adda24838266e92e runc: Version: 1.0.0-rc93+dev GitCommit: 0ae14750669f42209a1f974943408df754148e9d docker-init: Version: 0.19.0 GitCommit: b9f42a0
1.5 docker详细信息¶
root@StarFive:/usr/share/docker# docker info DEBU[2023-02-27T13:46:47.851609750Z] Calling HEAD /_ping DEBU[2023-02-27T13:46:47.855116250Z] Calling GET /v1.41/info Client: Context: default Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: dev Storage Driver: overlay2 Backing Filesystem: tmpfs Supports d_type: true Native Overlay Diff: false userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2 Default Runtime: runc Init Binary: docker-init containerd version: 969b3d638bbf5fe0296f7b80adda24838266e92e runc version: 0ae14750669f42209a1f974943408df754148e9d init version: b9f42a0 (expected: de40ad0) Kernel Version: 5.15.0-starlight-starlight Operating System: PolyOS PolyOS.1.0 OSType: linux Architecture: riscv64 CPUs: 4 Total Memory: 3.777GiB Name: StarFive ID: VVJY:KVKX:YI6Q:ZCTK:EXOS:TZWA:BC7R:DHRE:2HV6:ULWP:Y767:Y3KZ Docker Root Dir: /var/lib/docker Debug Mode: true File Descriptors: 24 Goroutines: 40 System Time: 2023-02-27T13:46:47.8568235Z EventsListeners: 0 Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://docker.mirrors.ustc.edu.cn/ Live Restore Enabled: true
2.运行docker¶
2.1 docker搜索镜像¶
root@StarFive:/etc/docker# docker search riscv64/ubuntu DEBU[2023-02-27T13:51:16.136250500Z] Calling HEAD /_ping DEBU[2023-02-27T13:51:16.138305750Z] Calling GET /v1.41/info DEBU[2023-02-27T13:51:16.169888500Z] Calling GET /v1.41/images/search?limit=25&term=riscv64%2Fubuntu DEBU[2023-02-27T13:51:16.170329750Z] hostDir: /etc/docker/certs.d/docker.io DEBU[2023-02-27T13:51:16.170450250Z] pinging registry endpoint https://index.docker.io/v1/ DEBU[2023-02-27T13:51:16.170497250Z] attempting v1 ping for registry endpoint https://index.docker.io/v1/ DEBU[2023-02-27T13:51:16.170560250Z] Index server: https://index.docker.io/v1/ NAME DESCRIPTION STARS OFFICIAL AUTOMATED riscv64/ubuntu Ubuntu is a Debian-based Linux operating sys… 1 root@StarFive:/etc/docker#
2.2 docker拉取镜像,仓库信息可在/etc/docker/daemon.json中配置¶
root@StarFive:/etc/docker# docker pull riscv64/ubuntu DEBU[2023-02-27T13:51:40.173094250Z] Calling HEAD /_ping Using default tag: latest DEBU[2023-02-27T13:51:40.174711000Z] Calling GET /v1.41/info DEBU[2023-02-27T13:51:40.207854500Z] Calling POST /v1.41/images/create?fromImage=riscv64%2Fubuntu&tag=latest DEBU[2023-02-27T13:51:40.219479500Z] hostDir: /etc/docker/certs.d/docker.mirrors.ustc.edu.cn DEBU[2023-02-27T13:51:40.219741250Z] Trying to pull riscv64/ubuntu from https://docker.mirrors.ustc.edu.cn/ v2 INFO[2023-02-27T13:51:40.491320750Z] Attempting next endpoint for pull after error: error parsing HTTP 403 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>403 Forbidden</title></head>\r\n<body>\r\n<center><h1>403 Forbidden</h1></center>\r\n<hr><center>openresty</center> \r\n</body>\r\n</html>\r\n" DEBU[2023-02-27T13:51:40.491444500Z] Trying to pull riscv64/ubuntu from https://registry-1.docker.io v2 DEBU[2023-02-27T13:51:43.726523500Z] (*service).Write started expected="sha256:f31546bc71659c643837d57f09a161f04e866b59da4f418e064082a756c4c23a" ref="manifest-sha256:f31546bc71659c643837d57f09a161f04e866b59da4f418e064082a756c4c23a" total=529 DEBU[2023-02-27T13:51:43.732612250Z] Fetching manifest from remote digest="sha256:f31546bc71659c643837d57f09a161f04e866b59da4f418e064082a756c4c23a" error="<nil>" remote="docker.io/riscv64/ubuntu:latest" DEBU[2023-02-27T13:51:44.423819250Z] Pulling ref from V2 registry: riscv64/ubuntu:latest DEBU[2023-02-27T13:51:44.427751750Z] pulling blob "sha256:7548465e3aa5fee0518ca5aefe07a54411b419ec670a320e18c9b8892b0afc0f" latest: Pulling from riscv64/ubuntu 7548465e3aa5: Downloading 27.53MB/27.75MB 7548465e3aa5: Download complete DEBU[2023-02-27T13:51:51.798431000Z] unpigz binary not found, falling back to go gzip library DEBU[2023-02-27T13:51:51.800709000Z] Applying tar in /var/lib/docker/overlay2/cdb3e571625bf4cff20ed8efc051b44f864e448071a6e695746990975c90e716/diff storage-7548465e3aa5: Extracting 27.75MB/27.75MB DEBU[2023-02-27T13:52:12.169188250Z] Applied tar sha256:8cbddf025c7e4817125cd04db0201ee2b87eb35a25cc7c8a8a7150047ad045b2 to cdb3e571625bf4cff20ed8efc051b44f87548465e3aa5: Pull complete DEBU[2023-02-27T13:52:12.173704000Z] Adding content digest to lease digest="sha256:f31546bc71659c643837d57f09a161f04e866b59da4f418e064082a756c4c23a" lease="moby-image-sha256:8b55084b9c02c8c6d013ed4b10f3e0c9306a50be9526ee8bf5870c8175554a72" remote="docker.io/riscv64/ubuntu:latest" Digest: sha256:f31546bc71659c643837d57f09a161f04e866b59da4f418e064082a756c4c23a Status: Downloaded newer image for riscv64/ubuntu:latest docker.io/riscv64/ubuntu:latest root@StarFive:/etc/docker# DEBU[2023-02-27T13:52:12.209107500Z] garbage collected d=1.171ms root@StarFive:/etc/docker# docker images DEBU[2023-02-27T13:55:13.999193250Z] Calling HEAD /_ping DEBU[2023-02-27T13:55:14.000774000Z] Calling GET /v1.41/images/json REPOSITORY TAG IMAGE ID CREATED SIZE riscv64/ubuntu latest 8b55084b9c02 2 months ago 61.6MB
2.3 docker本地导入镜像¶
root@StarFive:/usr/share/docker# docker load -i alpine.tar DEBU[2023-02-27T13:56:23.588254000Z] Calling HEAD /_ping DEBU[2023-02-27T13:56:23.606781750Z] Calling POST /v1.41/images/load?quiet=0 DEBU[2023-02-27T13:56:23.835557750Z] Applying tar in /var/lib/docker/overlay2/86a97fb3ff4145dd18073fffb1b7f595e148e09cad06fae493e6c655e9fe5a44/diff storage-driver=overlay2 7aa6590f795a: Loading layer 5.784MB/5.784MB DEBU[2023-02-27T13:56:25.335569500Z] Applied tar sha256:7aa6590f795ae949ee3acd4f5d87dfff4c73a4cfaadd557d939e33acc77b4b71 to 86a97fb3ff4145dd18073fffb1b7f595e148e09cad06fae493e6c655e9fe5a44, size: 5497569 Loaded image ID: sha256:ff0f616672b5dc760c8e78389081dc770b3dc0955b719d550f1442ab97718835 root@StarFive:/usr/share/docker# docker images DEBU[2023-02-27T13:56:29.455297000Z] Calling HEAD /_ping DEBU[2023-02-27T13:56:29.457514750Z] Calling GET /v1.41/images/json REPOSITORY TAG IMAGE ID CREATED SIZE riscv64/ubuntu latest 8b55084b9c02 2 months ago 61.6MB <none> <none> ff0f616672b5 3 months ago 5.5MB root@StarFive:/usr/share/docker# docker tag ff0f616672b5 riscv64/alpine:latest DEBU[2023-02-27T13:56:55.889882750Z] Calling HEAD /_ping DEBU[2023-02-27T13:56:55.891991500Z] Calling POST /v1.41/images/ff0f616672b5/tag?repo=riscv64%2Falpine&tag=latest root@StarFive:/usr/share/docker# docker images DEBU[2023-02-27T13:57:00.386926250Z] Calling HEAD /_ping DEBU[2023-02-27T13:57:00.388142500Z] Calling GET /v1.41/images/json REPOSITORY TAG IMAGE ID CREATED SIZE riscv64/ubuntu latest 8b55084b9c02 2 months ago 61.6MB riscv64/alpine latest ff0f616672b5 3 months ago 5.5MB
2.4 docker运行镜像¶
root@StarFive:/usr/share/docker# docker run -it riscv64/ubuntu DEBU[2023-02-27T13:58:05.864001250Z] Calling HEAD /_ping DEBU[2023-02-27T13:58:05.870531250Z] Calling POST /v1.41/containers/create DEBU[2023-02-27T13:58:05.871868250Z] form data: {"AttachStderr":true,"AttachStdin":true,"AttachStdout":true,"Cmd":null,"Domainname":"","Entrypoint":null, "Env":null,"HostConfig":{"AutoRemove":false,"Binds":null,"BlkioDeviceReadBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceWriteIOps": null,"BlkioWeight":0,"BlkioWeightDevice":[],"CapAdd":null,"CapDrop":null,"Cgroup":""[13000.106578] docker0: port 1(veth2c3c7f1) entered blocking state ,"CgroupParent":[13000.113067] docker0: port 1(veth2c3c7f1) entered disabled state "","CgroupnsMode[13000.120484] device veth2c3c7f1 entered promiscuous mode ":"","ConsoleSize":[0,0],"ContainerIDFile":"","CpuCount":0,"CpuPercent":0,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpuShares":0, "CpusetCpus":"","CpusetMems":"","DeviceCgroupRules":null,"DeviceRequests":null,"Devices":[],"Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd": null,"IOMaximumBandwidth":0,"IOMaximumIOps":0,"IpcMode":"","Isolation":"","KernelMemory":0,"KernelMemoryTCP":0,"Links":null,"LogConfig":{"Config":{},"Type":""}, "MaskedPaths":null,"Memory":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":-1,"NanoCpus":0,"NetworkMode":"default","OomKillDisable":false,"OomScoreAdj": 0,"PidMode":"","PidsLimit":0,"PortBindings":{},"Privileged":false,"PublishAllPorts":false,"ReadonlyPaths":null,"ReadonlyRootfs":false,"RestartPolicy": {"MaximumRetryCount":0,"Name":"no"},"SecurityOpt":null,"ShmSize":0,"UTSMode":"","Ulimits":null,"UsernsMode":"","VolumeDriver":"","VolumesFrom":null},"Hostname":"", "Image":"riscv64/ubuntu","Labels":{},"NetworkingConfig":{"EndpointsConfig":{}},"OnBuild":null,"OpenStdin":true,"Platform":null,"StdinOnce":true,"Tty":true,"User":" ","Volumes":{},"WorkingDir":""} DEBU[2023-02-27T13:58:05.899336500Z] container mounted via layerStore: &{/var/lib/docker/overlay2/8e42c2541d99c7ba8623bc204b3afbf20018427a6905cd66acce71b74146b81b/ merged 0x321cae0 0x321cae0} container=49624e56ba101059f485c726d94b401121d73b1c4cb60dbf7505e76d6e6c1dce DEBU[2023-02-27T13:58:05.904887750Z] Calling POST /v1.41/containers/49624e56ba101059f485c726d94b401121d73b1c4cb60dbf7505e76d6e6c1dce/attach?stderr=1&stdin=1&stdout= 1&stream=1 ...... [13000.736948] eth0: renamed from vethbaf6b17 [13000.806762] docker0: port 1(veth2c3c7f1) entered blocking state [13000.812785] docker0: port 1(veth2c3c7f1) entered forwarding state DEBU[2023-02-27T13:58:06.630008250Z] sandbox set key processing took 317.9555ms for container 49624e56ba101059f485c726d94b401121d73b1c4cb60dbf7505e76d6e6c1dce DEBU[2023-02-27T13:58:06.656567500Z] event forwarded ns=moby topic=/tasks/create type=containerd.events.TaskCreate DEBU[2023-02-27T13:58:06.658125500Z] event module=libcontainerd namespace=moby topic=/tasks/create DEBU[2023-02-27T13:58:06.699857750Z] event forwarded ns=moby topic=/tasks/start type=containerd.events.TaskStart DEBU[2023-02-27T13:58:06.700637000Z] event module=libcontainerd namespace=moby topic=/tasks/start root@49624e56ba10:/# root@49624e56ba10:/# DEBU[2023-02-27T13:58:19.274954000Z] Closing buffered stdin pipe DEBU[2023-02-27T13:58:19.275361500Z] attach: stdin: end DEBU[2023-02-27T13:58:19.275426500Z] attach: stdout: end DEBU[2023-02-27T13:58:19.275523500Z] attach: stderr: end DEBU[2023-02-27T13:58:19.276007500Z] attach done root@StarFive:/usr/share/docker# root@StarFive:/usr/share/docker# docker ps DEBU[2023-02-27T13:58:28.556189500Z] Calling HEAD /_ping DEBU[2023-02-27T13:58:28.557383750Z] Calling GET /v1.41/containers/json CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 49624e56ba10 riscv64/ubuntu "/bin/sh" 23 seconds ago Up 21 seconds unruffled_curran root@StarFive:/usr/share/docker# docker exec -it 49 /bin/sh DEBU[2023-02-27T13:58:53.186854500Z] Calling HEAD /_ping DEBU[2023-02-27T13:58:53.187916750Z] Calling GET /v1.41/containers/49/json DEBU[2023-02-27T13:58:53.196417500Z] Calling POST /v1.41/containers/49/exec DEBU[2023-02-27T13:58:53.197007250Z] form data: {"AttachStderr":true,"AttachStdin":true,"AttachStdout":true,"Cmd":["/bin/sh"],"Detach":false,"DetachKeys":"", "Env":null,"Privileged":false,"Tty":true,"User":"","WorkingDir":""} DEBU[2023-02-27T13:58:53.200305250Z] Calling POST /v1.41/exec/0dc65b1a1c03b0d8fbf05fff5235c4018b3ec7cf98af39a7743a84073929f518/start DEBU[2023-02-27T13:58:53.200680000Z] form data: {"Detach":false,"Tty":true} DEBU[2023-02-27T13:58:53.201408250Z] starting exec command 0dc65b1a1c03b0d8fbf05fff5235c4018b3ec7cf98af39a7743a84073929f518 in container 49624e56ba101059f485c726d94b401121d73b1c4cb60dbf7505e76d6e6c1dce DEBU[2023-02-27T13:58:53.212341000Z] attach: stdout: begin DEBU[2023-02-27T13:58:53.212891500Z] attach: stdin: begin DEBU[2023-02-27T13:58:53.231693250Z] event forwarded ns=moby topic=/tasks/exec-added type=containerd.events.TaskExecAdded DEBU[2023-02-27T13:58:53.232376500Z] event module=libcontainerd namespace=moby topic=/tasks/exec-added DEBU[2023-02-27T13:58:53.442344750Z] event forwarded ns=moby topic=/tasks/exec-started type=containerd.events.TaskExecStarted DEBU[2023-02-27T13:58:53.443023250Z] event module=libcontainerd namespace=moby topic=/tasks/exec-started root@49624e56ba10:/#