3

I am trying to run a container which runs an automated build. Here is the dockerfile:

   FROM ubuntu:14.04
    MAINTAINER pmandayam

    # update dpkg repositories
    RUN apt-get update

    # install wget
    RUN apt-get install -y wget

    # get maven 3.2.2
    RUN wget --no-verbose -O /tmp/apache-maven-3.2.2.tar.gz http://archive.apache.or
    g/dist/maven/maven-3/3.2.2/binaries/apache-maven-3.2.2-bin.tar.gz

    # verify checksum
    RUN echo "87e5cc81bc4ab9b83986b3e77e6b3095 /tmp/apache-maven-3.2.2.tar.gz" | md5
    sum -c

    # install maven
    RUN tar xzf /tmp/apache-maven-3.2.2.tar.gz -C /opt/
    RUN ln -s /opt/apache-maven-3.2.2 /opt/maven
    RUN ln -s /opt/maven/bin/mvn /usr/local/bin
    RUN rm -f /tmp/apache-maven-3.2.2.tar.gz
    ENV MAVEN_HOME /opt/maven

    # remove download archive files
    RUN apt-get clean

    # set shell variables for java installation
    ENV java_version 1.8.0_11
    ENV filename jdk-8u11-linux-x64.tar.gz
    ENV downloadlink http://download.oracle.com/otn-pub/java/jdk/8u11-b12/$filename

    # download java, accepting the license agreement
    RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie
    " -O /tmp/$filename $downloadlink

    # unpack java
    RUN mkdir /opt/java-oracle && tar -zxf /tmp/$filename -C /opt/java-oracle/
    ENV JAVA_HOME /opt/java-oracle/jdk$java_version
    ENV PATH $JAVA_HOME/bin:$PATH

    # configure symbolic links for the java and javac executables
    RUN update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 20000 &
    & update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000

    # install mongodb
    RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
    ' | sudo tee /etc/apt/sources.list.d/mongodb.list && \
            apt-get update && \
                apt-get --allow-unauthenticated install -y mongodb-org mongodb-org-s
    erver mongodb-org-shell mongodb-org-mongos mongodb-org-tools && \

                    echo "mongodb-org hold" | dpkg --set-selections && \
                        echo "mongodb-org-server hold" | dpkg --set-selections && \
                            echo "mongodb-org-shell hold" | dpkg --set-selections &&
     \
                                echo "mongodb-org-mongos hold" | dpkg --set-selectio
    ns && \
                                    echo "mongodb-org-tools hold" | dpkg --set-selec
    tions

    RUN mkdir -p /data/db
    VOLUME /data/db

    EXPOSE 27017

    COPY build-script /build-script

    CMD ["/build-script"]

I can build the image successfully but when I try to run the container I get this error:

$ docker run mybuild
no such file or directory
Error response from daemon: Cannot start container 3e8aa828909afcd8fb82b5a5ac894
97a537bef2b930b71a5d20a1b98d6cc1dd6: [8] System error: no such file or directory

what does it mean 'no such file or directory'?

Here is my simple script:

#!/bin/bash

sudo service mongod start

mvn clean verify

sudo service mongod stop

I copy it like this: COPY build-script /build-script

and run it like this: CMD ["/build-script"] not sure why its not working

3
  • if you remove from your Dockerfile the last line, rebuild it, that you start your container, docker exec in it, and launch /build-script does it work, or do you get the same error message? Commented Aug 12, 2015 at 19:21
  • What's the output of docker run mybuild ls -l /build-script? Commented Aug 12, 2015 at 19:24
  • I suspect it's just because the service stuff isn't going to work, but you may have another problem as well. Commented Aug 12, 2015 at 19:25

1 Answer 1

4

Using service isn't going to fly - the Docker base images are minimal and don't support this. If you want to run multiple processes, you can use supervisor or runit etc.

In this case, it would be simplest just to start mongo manually in the script e.g. /usr/bin/mongod & or whatever the correct incantation is.

BTW the lines where you try to clean up don't have much effect:

RUN rm -f /tmp/apache-maven-3.2.2.tar.gz
...
# remove download archive files
RUN apt-get clean

These files have already been committed to a previous image layer, so doing this doesn't save any disk-space. Instead you have to delete the files in the same Dockerfile instruction in which they're added.

Also, I would consider changing the base image to a Java one, which would save a lot of work. However, you may have trouble finding one which bundles the official Oracle JDK rather than OpenJDK if that's a problem.

Sign up to request clarification or add additional context in comments.

4 Comments

Hmm, I suspect there is another problem btw. Maybe your build-script file isn't the same directory as you're running your build from? I'd check it's really there and has executable permissions first. But the service stuff won't work at any rate.
It definitely is in the same directory as the pom.xml file, and I ran chmod 755 on "build-script". Now I am changing from sudo to the path to the executable (usr/bin/mongod) and will see how it goes
btw, how would I stop it then? since I can't run service stop?
Save the pid and use kill.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.