I'm running the following script from Bitbucket Pipelines:
#!/usr/bin/env bash
set -e
npm i
export docker_tag=${DOCKER_REGISTRY_HOST}/geolite2:latest
# Start Elasticsearch container
mkdir -p ${BITBUCKET_CLONE_DIR}/volumes/elasticsearch/usr/share/elasticsearch/data
docker run -d --rm \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-v ${BITBUCKET_CLONE_DIR}/volumes/elasticsearch/usr/share/elasticsearch/data:/usr/share/elasticsearch/data \
--name elasticsearch \
docker.elastic.co/elasticsearch/elasticsearch:6.2.3
# Download and unzip GeoLite2 database
curl -sS https://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip > geolite2.zip
apt-get update
apt-get -y install unzip
unzip geolite2.zip -d geolite2
# Wait until Elasticsearch is ready
echo "Waiting until Elasticsearch is ready."
for i in {1..99}; do
echo "Elasticsearch health check #${i}..."
curl -sS http://127.0.0.1:9200/_cluster/health?wait_for_status=green > /dev/null && break
docker ps -a
sleep 5
done
curl -sS http://127.0.0.1:9200/_cluster/health?wait_for_status=green > /dev/null || \
(echo "Elasticsearch failed to initialize. Aborting." && exit 1)
# Index GeoLite2 records from CSV file into Elasticsearch
node -e "require('./build/index-geolite2-database')('geolite2/$(ls geolite2)/GeoLite2-City-Blocks-IPv4.csv')"
# Stop Elasticsearch
docker stop elasticsearch
# Build an Elasticsearch GeoLite2 database image
docker build -t ${docker_tag} .
# Publish image to Docker registry
echo "${DOCKER_REGISTRY_PASSWORD}" | docker login -u ${DOCKER_REGISTRY_USERNAME} --password-stdin ${DOCKER_REGISTRY_HOST}
docker push ${docker_tag}
bitbucket-pipelines.yml:
image: node:9.10.0
pipelines:
custom:
Update Docker image:
- step:
name: Index and publish GeoLite2 database
services:
- docker
caches:
- node
script:
- ./build.sh
definitions:
services:
docker:
memory: 2048
The problem is that the Elasticsearch container doesn't seem to start at all. I keep getting the following output in the healthcheck for-loop:
Elasticsearch health check #32...
curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
As you can see, docker ps -a shows that no containers are running, nor have any started, which is surprising because I thought that docker run -d would at least wait until the container had started running.
Any idea what I'm doing wrong?
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.