Search code examples
dockerbuildgcloud

docker run fails with /bin/sh:0 -c requires an argument


I am trying to run a docker image

Dockerfile

FROM marketplace.gcr.io/google/ubuntu1804:latest
MAINTAINER Vinay Joseph (vinay.joseph@microfocus.com)
LABEL ACI_COMPONENT="License Server"
EXPOSE 20000/tcp

#Install Unzip
RUN apt-get install unzip

#Unzip License Server to /opt/MicroFocus
RUN mkdir /opt/MicroFocus
RUN cd /opt/MicroFocus

#Download the License Server
RUN curl -O https://storage.googleapis.com/software-idol-21/LicenseServer_12.1.0_LINUX_X86_64.zip
RUN chmod 777 LicenseServer_12.1.0_LINUX_X86_64.zip
RUN unzip LicenseServer_12.1.0_LINUX_X86_64.zip

cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/xxxx/idol-licenseserver', '.']
images:
- 'gcr.io/xxxx/idol-licenseserver'

The message i get is

docker run gcr.io/xxxx/idol-licenseserver 

/bin/sh: 0: -c requires an argument


Solution

  • There are a couple of problems with your Dockerfile

    First

    RUN apt-get install unzip
    

    A good practice is to perform an update before installing packages, otherwise you could fall into situation with missing package lists.

    RUN apt-get update && apt-get install -y ...
    

    Second

    RUN mkdir /opt/MicroFocus
    RUN cd /opt/MicroFocus
    

    This is mistake because cd doesn't work between layers (different RUN commands). What you wanted is achieved with single WORKDIR command

    WORKDIR /opt/MicroFocus
    

    Third

    The error message that you are facing means that base image is configured with something like ENTRYPOINT ["sh", "-c"] therefore expecting you to provide initial command line when launching this image. You have to define the proper startup command and append it to your command after image name.