Reputation: 3863
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
Reputation: 2442
Typically in your Dockerfile
you would:
COPY
your source files into your image.make
, etc...).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
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