0

I have a docker image that I want to use and reuse when it's updated. I want to avoid making any changes to the image itself to semi-automate the process of pulling the latest image and deploying containers based on it without having to jump through extra hoops.

Part of the process involves being able to modify the docker-entrypoint.sh file located in the container at

/usr/local/bin/docker-entrypoint.sh

My logic was to mount it as a bind mount point to a local file that I can edit as required - that way I don't have to update an image and commit every time an update to the original image is released to make changes to the docker-entrypoint.sh file.

I'm running the container with this command:

docker run -d --name test10-new  --mount type=bind,source=/data/docker-entrypoint.sh,target=/usr/local/bin/docker-entrypoint.sh new-test:latest

It runs fine without the mount, but with the mount it fails with only this in the log:

': No such file or directory

Any idea what could be going wrong? The local copy of docker-entrypoint.sh is executable. Thanks in advance!

wedwo
  • 338
  • 3
  • 11
  • The standard approach for this is to either use a date/version tag in your image name (essentially required if you're using a cluster environment like Kubernetes or AWS ECS) or to explicitly `docker pull yourimage:latest`. A Docker image is supposed to be self-contained, and if you also depend on having its source code outside the image, you're negating a significant part of the benefit. (And you never "commit" an image.) – David Maze Apr 13 '20 at 15:38
  • Understood, except it's not my image - i'm reusing someone else's. They've put in a lot of effort to streamiline the deployment process of upstream components in the image. The trouble I have is that I don't like their default entrypoint script so I want to replace it with my own and I may just resort to updating it each time I replace the image with the latest, then launch the container and run a Docker commit to take a snapshot to base my containers off. – wedwo Apr 13 '20 at 18:51
  • You can create a Dockerfile `FROM` any image you want, `COPY` your updated entrypoint script in, and (if it's changed) set a new `ENTRYPOINT` and `CMD`. There already being an entrypoint in the "base" image doesn't change the procedure. – David Maze Apr 13 '20 at 20:56

1 Answers1

0

For me, the --mount parameter needed an absolute path. You can provide this with "$(pwd)" or in my case (Makefile):

ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
up:
    docker run -it --mount type=bind,source="${ROOT_DIR}"/tmp/,target=/root/var/task/tmp/

In your case:

docker run -d --name test10-new --mount type=bind,source="$(pwd)"/data/docker-entrypoint.sh,target=/usr/local/bin/docker-entrypoint.sh new-test:latest

Thanks to How to get current relative directory of your Makefile?