【问题标题】:How to change the default directory docker uses to build an image如何更改 docker 用于构建映像的默认目录
【发布时间】:2021-12-21 16:28:01
【问题描述】:

我正在尝试设置一个 gitlab ci。

由于某些原因我没有“gitlab-runner”用户并且我没有对“/home/user_1”的权限,这是我的安装

/usr/local/bin/gitlab-runner install --user=user_1 --working-directory=/data/external/tmp/gitlab-runner

这就是我注册的方式

/usr/local/bin/gitlab-runner register --url GITLAB_URL --registration-token TOKEN

顺便说一下,我创建了这个 gitlab-ci.yml 文件:

stages:
  - deploy

deploy:
  stage: deploy
  # only:
  #  - 3.0.x
  script:
    - echo "deploying"
    - sudo docker build -t my_image:v1 .
    - echo "********Docker Images********"
    - sudo docker image list
    - echo "********End of Docker Images********"
    - sudo docker run -d -p 3000:5000 --rm --name my_container my_image:v1

  tags:
    - deploy

我收到此错误:

Error: error creating build container: Error committing the finished image:

error adding layer with blob "sha256:bb7d5a84853b217ac05783963f12b034243070c1c9c8d2e60ada47444f3cce04": 

Error processing tar file(exit status 1): 

Error setting up pivot dir: mkdir 

/home/user_1/.local/share/containers/storage/overlay/62a747bf1719d2d37fff5670ed40de6900a95743172de1b4434cb019b56f30b4/diff/.pivot_root436648414: 

permission denied

我想替换/home/user_1/.local/share/containers/storage/overlay/ 使用另一个地址,这样我就不会收到权限错误。

有什么建议吗?

我正在使用 Redhat Linux docker --version 是 podman 版本 3.2.3

码头信息:

server_name:/home/my_user[ 52 ] --> docker info
host:
  arch: amd64
  buildahVersion: 1.21.3
  cgroupControllers: []
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: conmon-2.0.29-1.module+el8.4.0+11822+6cc1e7d7.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.29, commit: ae467a0c8001179d4d0adf4ada381108a893d7ec'
  cpus: 8
  distribution:
    distribution: '"rhel"'
    version: "8.4"
  eventLogger: file
  hostname: server_name
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    uidmap:
    - container_id: 0
      host_id: 67298
      size: 1
  kernel: 4.18.0-305.3.1.el8_4.x86_64
  linkmode: dynamic
  memFree: 1818484736
  memTotal: 33444728832
  ociRuntime:
    name: runc
    package: runc-1.0.0-74.rc95.module+el8.4.0+11822+6cc1e7d7.x86_64
    path: /usr/bin/runc
    version: |-
      runc version spec: 1.0.2-dev
      go: go1.15.13
      libseccomp: 2.5.1
  os: linux
  remoteSocket:
    path: /run/user/67298/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_NET_RAW,CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: false
  slirp4netns:
    executable: /bin/slirp4netns
    package: slirp4netns-1.1.8-1.module+el8.4.0+11822+6cc1e7d7.x86_64
    version: |-
      slirp4netns version 1.1.8
      commit: d361001f495417b880f20329121e3aa431a8f90f
      libslirp: 4.3.1
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.1
  swapFree: 67353165824
  swapTotal: 67448598528
  uptime: 789h 40m 40.57s (Approximately 32.88 days)
registries:
  localhost:
    Blocked: false
    Insecure: true
    Location: localhost
    MirrorByDigestOnly: false
    Mirrors: []
    Prefix: localhost
  mkdcvtmaapp01:
    Blocked: false
    Insecure: true
    Location: server_name
    MirrorByDigestOnly: false
    Mirrors: []
    Prefix: server_name
  search:
  - registry.access.redhat.com
  - registry.redhat.io
  - docker.io
store:
  configFile: /home/my_user/.config/containers/storage.conf
  containerStore:
    number: 0
    paused: 0
    running: 0
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mount_program:
      Executable: /bin/fuse-overlayfs
      Package: fuse-overlayfs-1.6-1.module+el8.4.0+11822+6cc1e7d7.x86_64
      Version: |-
        fusermount3 version: 3.2.1
        fuse-overlayfs: version 1.6
        FUSE library version 3.2.1
        using FUSE kernel interface version 7.26
  graphRoot: /home/my_user/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: nfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 0
  runRoot: /run/user/67298/containers
  volumePath: /home/my_user/.local/share/containers/storage/volumes
version:
  APIVersion: 3.2.3
  Built: 1627570963
  BuiltTime: Thu Jul 29 11:02:43 2021
  GitCommit: ""
  GoVersion: go1.15.7
  OsArch: linux/amd64
  Version: 3.2.3

我也曾在我的 gitlab ci 中尝试过这三个,但没有奏效:

deploy:
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TMP: /data/external/tmp_docker_build
    TMPDIR: /data/external/tmp_docker_build

我也在.localsharecontainersstorage 上做了chmod 777,并在此溃败中覆盖了/home/user_1/.local/share/containers/storage/overlay/,但它仍然无法正常工作。

【问题讨论】:

  • 尝试设置环境变量DOCKER_DRIVER: overlay2 或者在你的runner的docker守护进程中配置它。
  • 您使用的是什么操作系统,您能否包含docker info 的输出?
  • @sytech 我正在使用 RedhatLinux。我在问题的末尾包含了 docker 信息。谢谢
  • @sytech 关于DOCKER_DRIVER: overlay2,我把结果加到了问题的最后
  • 这只是一个猜测:seccompProfilePath: /usr/share/containers/seccomp.json 中的内容是否允许写入用户主页?

标签: linux docker gitlab docker-build podman


【解决方案1】:

我以前也不知道这件事。显然,您可以通过将-g /path/to/dir 添加到 docker daemon 命令来设置 docker daemon 使用的数据目录。

例如,在 Ubuntu 或 Debian 系统上将 -g 添加到 /etc/default/docker 中的 DOCKER_OPTS

DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /data/external/docker"

我的来源是https://forums.docker.com/t/how-do-i-change-the-docker-image-installation-directory/1169 - 还有一个关于如何在 Fedora 或 CentOS 上完成此操作的注释:

编辑/etc/sysconfig/docker,并在other_args 变量中添加-g 选项:例如。 other_args="-g /var/lib/testdir"。如果有多个选项,请确保将它们附在 " " 中。重启后,(service docker restart) Docker 应该使用新目录。

【讨论】:

  • 我不希望更改系统上 Docker 的设置。那么,根据你的解决方案,我的gitlab-ci.yml文件sudo docker build -t my_image:v1 .这行代码应该是什么,而我的系统是redhat linux
  • 不,更改 docker 客户端命令不会改变 docker 守护进程写入内容的位置,因为客户端只会告诉守护进程要做什么,但不会影响守护进程的执行位置。
  • 我的系统中没有/etc/sysconfig/docker
猜你喜欢
  • 1970-01-01
  • 2015-01-05
  • 2021-10-20
  • 2020-12-06
  • 1970-01-01
  • 2014-01-27
  • 2020-12-20
  • 2021-02-06
  • 2018-04-08
相关资源
最近更新 更多