简体   繁体   English

编辑默认泊坞窗图像“Hello-world”的内容

[英]Edit content of default docker image "Hello-world"

I am a Docker newbie.我是 Docker 新手。

My problem is to change the default text of image 'hello-world' from "Hello from Docker!..." to something else eg "Hello guys".我的问题是将图像“hello-world”的默认文本从“Hello from Docker!...”更改为其他内容,例如“Hello Guys”。

Some of solutions I have found on the internet must download some editors like vim or vs code then edit the dockerfile (!?);我在互联网上找到的一些解决方案必须下载一些编辑器,如 vim 或 vs code,然后编辑 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).因为我只想通过终端解决这个问题(我使用 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.这里唯一要理解的重要一点是hello-world映像是scratch构建的,并且只包含一个严格的最小二进制文件。 So it is not really suitable to be extended through a Dockerfile.所以它并不适合通过 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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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