How to run docker-compose on AWS CodeBuild?
Okay, I figured out the issue!
You need to enable 'Privileged Access' on the CodeBuild container. This will allow you to interact with the docker cli.
Then add these two lines to the install commands:
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2&
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
`
ex:
version: 0.2
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 15 sh -c "until docker info; do echo .; sleep 1; done"
pre_build:
commands:
- docker build -t helloworld .
build:
commands:
- docker images
- docker run helloworld echo "Hello, World!"
Are you using the Docker runtime for your build environment?
I am working with this repo: https://github.com/mreferre/yelb
That dockercompose isn't building anything (it's rather meant to deploy) but I believe you are hitting a problem much before that. Your compose up should work if you use the Docker runtime.
This is what my buildspec looks like:
version: 0.2
phases:
build:
commands:
- cd deployments/platformdeployment/Docker
- docker-compose up -d
And this is the output:
[Container] 2019/02/20 13:48:02 Waiting for agent ping
[Container] 2019/02/20 13:48:04 Waiting for DOWNLOAD_SOURCE
[Container] 2019/02/20 13:48:07 Phase is DOWNLOAD_SOURCE
[Container] 2019/02/20 13:48:07 CODEBUILD_SRC_DIR=/codebuild/output/src292484508/src/github.com/mreferre/yelb
[Container] 2019/02/20 13:48:07 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2019/02/20 13:48:07 Processing environment variables
[Container] 2019/02/20 13:48:07 Moving to directory /codebuild/output/src292484508/src/github.com/mreferre/yelb
[Container] 2019/02/20 13:48:07 Registering with agent
[Container] 2019/02/20 13:48:07 Phases found in YAML: 1
[Container] 2019/02/20 13:48:07 BUILD: 2 commands
[Container] 2019/02/20 13:48:07 Phase complete: DOWNLOAD_SOURCE Success: true
[Container] 2019/02/20 13:48:07 Phase context status code: Message:
[Container] 2019/02/20 13:48:07 Entering phase INSTALL
[Container] 2019/02/20 13:48:07 Phase complete: INSTALL Success: true
[Container] 2019/02/20 13:48:07 Phase context status code: Message:
[Container] 2019/02/20 13:48:08 Entering phase PRE_BUILD
[Container] 2019/02/20 13:48:08 Phase complete: PRE_BUILD Success: true
[Container] 2019/02/20 13:48:08 Phase context status code: Message:
[Container] 2019/02/20 13:48:08 Entering phase BUILD
[Container] 2019/02/20 13:48:08 Running command cd deployments/platformdeployment/Docker
[Container] 2019/02/20 13:48:08 Running command docker-compose up -d
Creating network "docker_yelb-network" with driver "bridge"
Pulling redis-server (redis:4.0.2)...
4.0.2: Pulling from library/redis
Pulling yelb-db (mreferre/yelb-db:0.3)...
0.3: Pulling from mreferre/yelb-db
Pulling yelb-appserver (mreferre/yelb-appserver:0.3)...
0.3: Pulling from mreferre/yelb-appserver
Pulling yelb-ui (mreferre/yelb-ui:0.3)...
0.3: Pulling from mreferre/yelb-ui
Creating docker_redis-server_1 ...
Creating docker_yelb-db_1 ...
·[2A·[2K
Creating docker_redis-server_1 ... ·[32mdone·[0m
·[2B·[1A·[2K
Creating docker_yelb-db_1 ... ·[32mdone·[0m
·[1BCreating docker_yelb-appserver_1 ...
·[1A·[2K
Creating docker_yelb-appserver_1 ... ·[32mdone·[0m
·[1BCreating docker_yelb-ui_1 ...
·[1A·[2K
Creating docker_yelb-ui_1 ... ·[32mdone·[0m
·[1B
[Container] 2019/02/20 13:49:00 Phase complete: BUILD Success: true
[Container] 2019/02/20 13:49:00 Phase context status code: Message:
[Container] 2019/02/20 13:49:00 Entering phase POST_BUILD
[Container] 2019/02/20 13:49:00 Phase complete: POST_BUILD Success: true
[Container] 2019/02/20 13:49:00 Phase context status code: Message: