How do I copy my application and all of its parts into a Docker Image?

I’m sorry if this is a repeat or very newbish. This must be simple and I’m just overlooking something.

I’ve built an app. It required a package, libwebsockets-dev, that had to be installed using apt-get install. So I have those on my system. The make file puts my app in /usr/local/sbin, it puts the app config file somewhere else, and also creates some data and log folders. Anyway, everything builds and executes properly on my host machine.

So now I want to get my app into my Docker image. I understand the COPY command works from the current context. But is the current context the only place I can copy files from? Neither application binary, nor anything else associated with it is in my work folder.

So how do I copy files that are not in my current context into the Docker image? Or do I have to copy them into the current context before starting the docker build? Or do I have to pull all the sources into the Docker image and build them there? Or am I missing some critical packaging step where I need to somehow bundle my application and its dependencies and pass it over to Docker somehow?

I have the rest of my Dockerfile doing exactly what it’s supposed to do. I just can’t figure out how to move my application into the image.

Advice?

I figured it out I think. 1) I copied my application binary and config files to the local context. 2) In my Dockerfile I added copy commands to place these in the appropriate locations. 3) In my Dockerfile I added some apt-get update and install commands to pull in the appropriate libraries. 4) In my Dockerfile I built out any directory structures that had to be there.

Depending on how your application is set up, one convention in GNU makefiles is to use a DESTDIR variable to tell them to install somewhere else, but with their normal directory layout. This would look something like so:

./configure --prefix=/usr/local
make
mkdir x
make install DESTDIR=$PWD/x
cd x
tar cvzf ../app.tar.gz .
cd ..
tar tvzf app.tar.gz

What you will see in the last line is that the tar file has paths like ./usr/local/sbin/my_app. Then you can copy that file into your Docker build tree (context directory) and ADD it.

IME it’s not uncommon to just build the whole application from within the Dockerfile, though this requires your container having a toolchain, which you may not want for size and/or aesthetic reasons.