docker - Alpine:等待docker启动后再继续
问题描述
我正在为我的 CI/CD 机器使用 Alpine linux。下面的docker文件:
FROM node:10.15-alpine
RUN npm i -g sequelize sequelize-cli mysql2
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update
RUN apk add --update git bash openssh terraform aws-cli docker openrc
WORKDIR /var/app
问题是当 CI 尝试执行 docker 代码时,例如。docker login
, 它失败:
[Container] 2019/01/10 11:18:10 Running command $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2019/01/10 11:18:10 Command did not exit successfully $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) exit status 1
当我尝试添加该行时
RUN service docker start
我让码头工人已经开始了
那我该如何等待 docker 启动呢?
解决方案
请考虑@DavidMaze 的答案,据说 DinD 不是正确的方法,但我认为这似乎更容易......此外,我在 AWS 上找到了有关如何完成这项工作的文档。
https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker-custom-image.html
我学到的关键点是我需要在 CodeBuild 上启用特权模式,然后在我的 buildspec 中,我需要这样做:
phases:
install:
commands:
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2&
- timeout -t 15 sh -c "until docker info; do echo .; sleep 1; done"
推荐阅读
- android - 如何通过kivy向android应用程序添加字体?
- typescript - Typescript 中元组参数的文字值
- ruby-on-rails - Rails App:建模两个用户模型的最佳方式(如 Uber)。设计?1 轮廓模型?
- buffer - 检测边界并在两个方向上重置循环缓冲区指针
- java - System.out.print() 读取 Scanner 错误
- javascript - 切换对象javascript的值
- sql-server - 无法将 SQL Server 连接到 Crystal Report 8.5
- python - Python 3.7 input() 不起作用,但 raw_input 起作用
- javascript - 如何使用条件循环函数
- python - 二维数组中给定位置的最小项目