user1584421
user1584421

Reputation: 3863

Make install in Dockerfile

I want to build a docker image, via a dockerfile.

There is one particular application, i would like the dockerfile to have.

The way i install this application is i have some cmake files, and i use make, install.

I want to have this functionality inside the dockefile. In other words, when the dockerfile is built, i want to have the application already installed in my image.

How do i handle the file management thing in the dockerfile?

I know that when i deal with the RUN command, i can mount filesystems, from the docker host to the docker image. But i am not exactly interested in that now, since the files that the dockerfile will use, are only for building the application, and nothing else.

Upvotes: 0

Views: 20815

Answers (1)

kthompso
kthompso

Reputation: 2442

Typically in your Dockerfile you would:

  1. COPY your source files into your image.
  2. Install your necessary tools (make, etc...).
  3. RUN make to build and install your application.

A basic Dockerfile might be:

FROM ubuntu

# Copy your source file directory into /app
COPY path/to/source /app/

# Install make
RUN apt update && apt install -y make

# Change to /app
WORKDIR /app

# run make
RUN make install

Example

As a simple example lets say I have this makefile that builds and installs an application called sayhi:

install:
        echo -n "#!/bin/bash\necho hello world" >> /usr/local/bin/sayhi
        chmod +x /usr/local/bin/sayhi

Using this Dockerfile in the same directory, I build my image using docker build --tag sayhi .

FROM ubuntu

COPY . /app/

RUN apt update && apt install -y make

WORKDIR /app

RUN make install

# Set the default command to run my application
CMD ["sayhi"]

Then I can run my docker container like so:

$ docker run sayhi
hello world

Upvotes: 7

Related Questions