Issue
I am a Docker newbie.
My problem is to change the default text of image 'hello-world' from "Hello from Docker!..." to something else e.g "Hello guys".
Some of solutions I have found on the internet must download some editors like vim or vs code then edit the dockerfile (!?); or create a new container and change the default path to a new one (!?). I tried some but not work or some are not suitable. Because I only want to solve this only through Terminal (I use ubuntu server 20.4).
Thanks in advance!
Solution
I decided to answer since this looked like a fun quest. But I voluntarily included very few details because this looks like an assignment question and you should make your own journey to understand how all this works exactly. If this not an assignment, well you need to walk your path as well ! :)
Anyhow, I had no knowledge of the internals of this image and my only point of start was the official image page from where I just followed the "spaghetti" finding resources, reading existing code and testing some commands.
The only important thing to understand here is that the hello-world
image is built from scratch
and only contains a strict minimal binary. So it is not really suitable to be extended through a Dockerfile.
This is how I solved it using the command line only. Note: you might have to install some needed tools if you encounter errors while running the below but understanding which one and how is part of your journey too.
git clone https://github.com/docker-library/hello-world
cd hello-world
echo "Hello Guys!" > greetings/hello-world.txt
./update.sh
# Change below with your correct architecture if different
cd amd64/hello-world
docker build -t my_hello_world:latest .
docker run --rm my_hello_world:latest
Which gives (last step only):
$ docker run --rm my_hello_world:latest
Hello Guys!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Answered By - Zeitounator Answer Checked By - Willingham (WPSolving Volunteer)