Friday, June 29, 2018

Howto modify an docker image that was created from an existing one

Based on a howto, i created a new image based on an existing one.
now i don´t have a Dockerfile and there are things happening, when the container starts
I cannot change - that´s how it looks to me.
Is there a way to modify things that have been setup in the Dockerfile of the base image I have used ?
for example: the container runs a bash script when it starts, i want to change this.
 
----------------
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:
  1. Create an empty directory and copy or create script.sh in it
  2. Create Dockerfile with following content:
    FROM repo/image
    ADD script.sh /
    ENTRYPOINT /script.sh
  3. docker build -t="myimage" .
  4. docker run myimage
Notes:
  • When running the container (step 4), it's no longer necessary to specify --entrypoint since we have it defaulted in the Dockerfile.
  • 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 ;-)
 

No comments:

Post a Comment

Manage Docker as a non-root user

  The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user   root   and other users ...