Sameh Sharaf
Sameh Sharaf

Reputation: 1131

Unable to download docker golang image: No command specified

Newbie in docker here.

I want to build a project using go language and my docker-compose.yml file has the following:

go:
    image: golang:1.7-alpine
    volumes:
      - ./:/server/http
    ports:
        - "80:8080"
    links:
        - postgres
        - mongodb
        - redis
    environment:
        DEBUG: 'true'
        PORT: '8080'

When I run docker-compose up -d in terminal, it returns the following error:

`ERROR: for go  Cannot create container for service go: No command specified`

How should I fix it?

Upvotes: 1

Views: 528

Answers (3)

Sameh Sharaf
Sameh Sharaf

Reputation: 1131

I solved it by using golang:1.7 instead of golang:1.7-alpine.

Upvotes: 1

VonC
VonC

Reputation: 1323115

You should run your container with an argument which will be passed to the default ENTRYPOINT, to be executed as a command

But the best practice these days is to use multistage, in order to generate a smaller image with just your application.

Or you can define your ENTRYPOINT being your build Go application.

See 'Using Docker Multi-Stage Builds with Go ', using the new AS build-stage keyword.

Your Dockerfile would be:

# build stage
ARG GO_VERSION=1.8.1  
FROM golang:${GO_VERSION}-alpine AS build-stage  
MAINTAINER [email protected]  
WORKDIR /go/src/github.com/frankgreco/gobuild/  
COPY ./ /go/src/github.com/frankgreco/gobuild/  
RUN apk add --update --no-cache \  
        wget \
        curl \
        git \
    && wget "https://github.com/Masterminds/glide/releases/download/v0.12.3/glide-v0.12.3-`go env GOHOSTOS`-`go env GOHOSTARCH`.tar.gz" -O /tmp/glide.tar.gz \
    && mkdir /tmp/glide \
    && tar --directory=/tmp/glide -xvf /tmp/glide.tar.gz \
    && rm -rf /tmp/glide.tar.gz \
    && export PATH=$PATH:/tmp/glide/`go env GOHOSTOS`-`go env GOHOSTARCH` \
    && glide update -v \
    && glide install \
    && CGO_ENABLED=0 GOOS=`go env GOHOSTOS` GOARCH=`go env GOHOSTARCH` go build -o foo \
    && go test $(go list ./... | grep -v /vendor/) \
    && apk del wget curl git

# production stage
FROM alpine:3.5  
MAINTAINER [email protected]  
COPY --from=build-stage /go/src/github.com/frankgreco/go-docker-build/foo .  
ENTRYPOINT ["/foo"]  

Upvotes: 0

user2915097
user2915097

Reputation: 32156

Golang:1.7-alpine is just a basis for building a Go container, and does not have a CMD or an ENTRYPOINT, so ends immediately.

Use an image doing really something, like printing hello world every 45 seconds

Upvotes: 1

Related Questions