docker日常使用

cooolr 于 2022-09-16 发布

安装

sudo apt-get install docker-compose

基础

进阶

$ sudo mkdir -p /etc/systemd/system/docker.service.d
$ cat /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:10809"
Environment="HTTPS_PROXY=http://127.0.0.1:10809"

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
docker build -t image_name . --network host \
        --build-arg http_proxy=http://127.0.0.1:10809 \
        --build-arg https_proxy=http://127.0.0.1:10809

跨平台容器

  1. 获取QEMU
  2. 复制命令到系统路径

     sudo cp qemu-arm-static /usr/bin/
     sudo chmod +x /usr/bin/qemu-arm-static
    
  3. 注册QEMU虚拟机 [重启电脑后需要重新执行注册]

     docker run --rm --privileged multiarch/qemu-user-static:register
    
  4. 下载armv7镜像

     sudo docker pull ubuntu@sha256:02ef83b72fb2fb709c356d0669a433555bcc5d07e31dc0016d036f1ca201bf13
    
  5. 创建arm容器

     sudo docker run -itd \
     -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static \
     -v /etc/timezone:/etc/timezone:ro \
     -v /etc/localtime:/etc/localtime:ro \
     -v /home/pi/codespace:/codespace \
     b7071f5bf0df
    
  6. 测试容器架构

     root@8674accc718a:/# uname -m
     aarch64