By following a how-to, I've created a new image based on an existing one.
I don´t have the original images' Dockerfile and there are things happening when the container starts that
I can't change - that´s how it seems anyway.
Is there a way to modify the commands in the Dockerfile of the base image?
For example the container runs a bash script when it starts, I want to change this.
Docker images can now be edited simply and reliably. This is an example of a Dockerfile for a Zabbix monitoring container. To change the image used by an existing container, we must first delete it, then edit the Docker file to make the necessary changes, and then recreate the container using the new file.
Docker doesn't do merges of the images, but there isn't anything stopping you combining the dockerfiles if available, and rolling into them into a fat image which you'd need to build.
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
:
script.sh
in itCreate Dockerfile
with following content:
FROM repo/image
ADD script.sh /
ENTRYPOINT /script.sh
docker build -t="myimage" .
docker run myimage
Notes:
--entrypoint
since we have it defaulted in the Dockerfile
.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.
If launching the container with the command from the tutorial fails, your base image most likely introduced an ENTRYPOINT. Any commands you specify for docker run
will be appended as options to the ENTRYPOINT command. Thus, given an ENTRYPOINT of e.g. /usr/bin/somescript
,
docker run -d --name newguest -p 8080:80 mymod/httpd:v1 /usr/sbin/httpd -D FOREGROUND
will cause the container to execute
/usr/bin/somescript /usr/sbin/httpd -D FOREGROUND
instead of
/usr/sbin/httpd -D FOREGROUND
To get rid of the ENTRYPOINT, use the --entrypoint
option:
docker run --entrypoint "" -d --name newguest -p 8080:80 mymod/httpd:v1 /usr/sbin/httpd -D FOREGROUND
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With