1

I'm trying to compile a C++ program using cmake in ubuntu containerized in Docker. Without Docker I can make it work just fine, but with it I seem to get some errors, whowever I can't seem to fix them :/

I've tried resolving to change the path to many different combinations in the hopes that I was just writing in the wrong path.

FROM ubuntu:16.04

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in the requirements.txt
RUN apt-get update && apt-get -y install g++ make cmake-curses-gui libsqlite3-dev libmariadb-client-lgpl-dev subversion

# Make port 8078 available to the world outside this container
EXPOSE 8078

# Retrieve EOServ and build it
RUN svn checkout svn://eoserv.net/eoserv/trunk/ /app/eoserv
RUN cd /app/eoserv && mkdir build && cd build
RUN cmake -G "Unix Makefiles" /app/eoserv
RUN make

# Run ./eoserv when the container launches
RUN /app/eoserv/eoserv
# Here I've tried several options like
# RUN ./eoserv
# RUN cd /app/eoserv && ./eoserv

Expected results would be an eoserv binary in desired folder, it works when I don't run it in the docker image, but cmake it all by itself, without Docker. Actual results are:

[ 91%] Building C object CMakeFiles/eoserv.dir/tu/sha256.c.o
[100%] Linking CXX executable eoserv
/usr/bin/ld: cannot open output file eoserv: Is a directory
collect2: error: ld returned 1 exit status
CMakeFiles/eoserv.dir/build.make:305: recipe for target 'eoserv' failed
make[2]: *** [eoserv] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/eoserv.dir/all' failed
make[1]: *** [CMakeFiles/eoserv.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
The command '/bin/sh -c make' returned a non-zero code: 2

1 Answer 1

2

The RUN instruction starts a new shell. So the commands you RUN previously will only be local to that shell, which includes things like cd, and the next RUN instruction will start a new shell without knowledge of the previous.

The instructions

RUN cd /app/eoserv && mkdir build && cd build
RUN cmake -G "Unix Makefiles" /app/eoserv
RUN make

needs to be combined into a single RUN instruction

RUN cd /app/eoserv && mkdir build && cd build && cmake -G "Unix Makefiles" /app/eoserv && make

You could of course write a script which runs the commands, and invoke that script with the RUN instruction.

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

6 Comments

Thanks that fixed something at least, however, now I'm getting this error: Step 9/9 : RUN cd /app/eoserv && ./eoserv Running in 6f4e36529644 /bin/sh: 1: ./eoserv: not found The command '/bin/sh -c cd /app/eoserv && ./eoserv' returned a non-zero code: 127
@MatiasPersson Unfortunately no. You might want to post a new question about that issue.
Thanks, I asked the person beneath me before asking new question on the site :)
@MatiasPersson Please remember that this site isn't only for you, it's for everyone who might have similar problems. By posting a brand new question it will be easier for other to find it and the possible solution.
That's true. I'll try to ask a new question then, to see if I can get a response there.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.