Modifying a docker image that was created from an existing one
Just create a new Dockerfile in an empty Directory. Start the Dockerfile with
FROM repo/image
where 'repo/image' is the id of the image your are currently using.
and add your customizations below.
This way you build a new image that is based on another image.
In particular, to change the command that runs at startup, put in a CMD and/or ENTRYPOINT line.
To answer your specific q: "the container runs a bash script when it starts, i want to change this". Let's assume you want to run /script.sh
(part of the image) instead of the default, you can instantiate a container using:
docker run --entrypoint /script.sh repo/image
If script.sh
isn't part of the image and/or you prefer not having to specify it explicitly each time with --entrypoint
as above, you can prepare an image that contains and runs your own script.sh
:
- Create an empty directory and copy or create
script.sh
in it Create
Dockerfile
with following content:FROM repo/image ADD script.sh / ENTRYPOINT /script.sh
docker build -t="myimage" .
docker run myimage
Notes:
- When running the container (step 4), it's no longer necessary to specify
--entrypoint
since we have it defaulted in theDockerfile
. - It's really that simple; no need to sign up to docker hub or any such thing (although it's of course recommended in time ;-)