简体   繁体   中英

Edit content of default docker image "Hello-world"

I am a Docker newbie.

My problem is to change the default text of image 'hello-world' from "Hello from Docker!..." to something else eg "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!

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM