I have a curious situation where my docker-compose build won't complete when I use dockerize
to wait for databases etc to be ready, and use dep
to load my Go dependencies.
Here's an extract from docker-compose.yml (there are mosquitto, postgres, and python containers in addition to the golang container shown below)
version '3.3'
services:
foobar_container:
image: foobar_image
container_name: foobar
build:
context: ./build_foobar
dockerfile: Dockerfile.foobar
#command: dockerize -wait tcp://mosquitto:1883 -wait tcp://postgres:5432 -timeout 200s /go/src/foobar/main
volumes:
- ./foobar:/go
stdin_open: true
tty: true
external_links:
- mosquitto
- postgres
ports:
- 1833
- 8001
depends_on:
- mosquitto
- postgres
Here's my Dockerfile.foobar
FROM golang:latest
WORKDIR /go
RUN apt-get update && apt-get install -y wget mosquitto-clients net-tools
ENV DOCKERIZE_VERSION v0.6.0
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
ADD foobar.sh /foobar.sh
#RUN go build main.go
RUN chmod +x /foobar.sh
Here's my build script foobar.sh:
#!/bin/bash
mkdir -p /go/bin # required directory that may have been overwriten by docker-compose `volumes` param
echo "++++++++ Downloading Golang dependencies ... ++++++++"
cd /go/src/foobar
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
echo "++++++++ Installing Golang dependencies ... ++++++++"
dep ensure
echo "++++++++ Testing MQTT message broker ... ++++++++"
until [[ $(mosquitto_sub -h "mosquitto" -t '$SYS/#' -C 1 | cut -c 1-9) = "mosquitto" ]]; do
echo "++++++++ Message broker is not ready. Waiting one second... ++++++++"
sleep 1
done
echo "++++++++ Building application... ++++++++"
go build main.go
If I uncomment the command
line of docker-compose.yml
my foobar.sh
won't run past the curl
line. No error is outputted, the execution just stops.
If I comment from curl
onwards, and uncomment the command
line, I can setup to completion (however the foobar
container needs to me started manually). My python container (which depends on all postgres, go, and mosquitto containers) sets up fine.
What's going wrong?