1

I would like to add a custom binary executable to one of my containers. I made it on my machine and am trying to add it. At first, I thought about mounting some directory as /tmp/foo and just copy it to /usr/bin/. Not very nice but should do the trick. To do so I defined the following volume mounting in docker-compose.yml:

volumes:
  - ./var/bin/:/tmp/bin/

and the following command in Dockerfile:

RUN ls /tmp/bin

RUN cp /tmp/bin/wkhtmltoimage /usr/local/bin/ && cp /tmp/bin/wkhtmltopdf /usr/local/bin/

As you can see I already added listing directory to check if anything's there and I got

ls: cannot access /tmp/bin: No such file or directory
ERROR: Service 'web' failed to build: The command '/bin/sh -c ls /tmp/bin' returned a non-zero code: 2

Now, here are two questions:

  1. Why is this directory not visible in the container's command line? The other mounts are available...

  2. How can I achieve this goal "properly"? So that the binary would be copied/set once during image build and wouldn't require a mapping on every container run?

1 Answer 1

2

Why is this directory not visible in the container's command line? The other mounts are available...

Because the bind mount volume hasn't been mounted when you're building your container. You are mounting a volume at runtime by using the docker-compose.yml, akin to

docker run -v $(pwd)/var/tmp:/tmp/bin myimage/myimage

But you're trying to access /tmp/bin during the build, before docker-compose mounts the volume.

How can I achieve this goal "properly"? So that the binary would be copied/set once during image build and wouldn't require a mapping on every container run?

Replace the two RUN commands you supplied from your Dockerfile with a pair of ADD commands:

ADD ./var/bin/wkhtmltopdf /usr/local/bin
ADD ./var/bin/wkhtmltoimage /usr/local/bin

This will take the files from your host and put them directly in the image. This is the proper way to do what you want.

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

2 Comments

I;m out of the office already but I'll try it very first thing in the morning! :) One more thing BTW. The other container I am preparing is a database... this might be trivial but how should I load sql dump into fresh db instance on first build? :)
Great, good luck :D Probably best to ask a new question re: a sql dump versus sussing it out in the comments.

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.