12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCI2.0 のDocker環境からAWS ECRにpushする

Posted at

CircleCI1.0からCircleCI2.0への移行作業中、ECRへのpushでハマった。

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?
Exited with code 1

ようやく解決したので備忘録として記事に残します。

CircleCI1.0でのECRデプロイコード

CircleCIの設定画面から
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEYをセットしておく

circle.yml
machine:
  services:
    - docker
  node:
    version: 6.0.0
  environment:
    AWS_ID: {ここにAWS ACCOUNT ID}

dependencies:
  override:
    - npm install

test:
  override:
    - npm run build

deployment:
  development:
    branch: master
    commands:
      - $(aws ecr get-login --region ap-northeast-1)
      - docker build -t hogehoge:fuga-$CIRCLE_SHA1 .
      - docker tag hogehoge:fuga-$CIRCLE_SHA1 ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1
      - docker push ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1

CircleCI2.0 での書き方(ボツ)

頑張って2.0に置き換えてみた

.circleci/config.yml
version: 2
defaults: &defaults
  working_directory: ~/workspace
  docker:
    - image: circleci/python:2.7-node-browsers
      environment:
        AWS_ID: {ここにAWS ACCOUNT ID}

jobs:
  ecr:
    <<: *defaults
    steps:
      - checkout
      - run: npm install
      - run: npm run build
      - run: sudo pip install awscli
      - run: $(aws ecr get-login --region ap-northeast-1 --no-include-email)
      - run: docker build -t hogehoge:fuga-$CIRCLE_SHA1 .
      - run: docker tag hogehoge:fuga-$CIRCLE_SHA1 ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1
      - run: docker push ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1

# Workflows
workflows:
  version: 2
  ecr_push:
    jobs:
      - ecr:
          filters:
            branches:
              only: /^master/

Docker daemonがいないと怒られてしまった。

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

error.png

CircleCI2.0 での書き方(正)

丸一日悩んだ結果、公式ドキュメントに setup_remote_docker を発見。
これで Docker in Dockerが実現するらしい。

.circleci/config.yml
version: 2
defaults: &defaults
  working_directory: ~/workspace
  docker:
    - image: circleci/python:2.7-node-browsers
      environment:
        AWS_ID: {ここにAWS ACCOUNT ID}

jobs:
  ecr:
    <<: *defaults
    steps:
      - checkout
      # Docker in Docker
      - setup_remote_docker # コレを書くことでDocker上にDockerが立ち上がる
      - run: npm install
      - run: npm run build
      - run: sudo pip install awscli
      - run: $(aws ecr get-login --region ap-northeast-1 --no-include-email)
      - run: docker build -t hogehoge:fuga-$CIRCLE_SHA1 .
      - run: docker tag hogehoge:fuga-$CIRCLE_SHA1 ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1
      - run: docker push ${AWS_ID}.dkr.ecr.ap-northeast-1.amazonaws.com/hogehoge:fuga-$CIRCLE_SHA1

# Workflows
workflows:
  version: 2
  ecr_push:
    jobs:
      - ecr:
          filters:
            branches:
              only: /^master/
12
11
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?