Hello world in a container

GTK3学习笔记2 Hello World in GTK+ 上节讲了在Windows上建立GTK3的codeblocks开发环境,这节讲Example 1. Hello World in GTK+。 例子很简单,实现了窗口和一个普通按钮,效果如图: 源代码如下,有很简单的英文注释,容易看懂,就不翻译了: #include /* 下面是两个回调函数 */ static void print_hello (GtkWidget *widg 阅读详情

Hello world in a container

So what’s this Docker thing all about?

Docker allows you to run applications, worlds you create, inside containers.Running an application inside a container takes a single command: docker run.

Note: Depending on your Docker system configuration, you may be required topreface each docker command on this page with sudo. To avoid this behavior,your system administrator can create a Unix group called docker and add usersto it.

Run a Hello world

Let’s try it now.

$ docker run ubuntu:14.04 /bin/echo 'Hello world'
Hello world

And you just launched your first container!

So what just happened? Let’s step through what the docker run commanddid.

First we specified the docker binary and the command we wanted toexecute, run. The docker run combination runs containers.

Next we specified an image: ubuntu:14.04. This is the source of the containerwe ran. Docker calls this an image. In this case we used an Ubuntu 14.04operating system image.

When you specify an image, Docker looks first for the image on yourDocker host. If it can’t find it then it downloads the image from the publicimage registry: Docker Hub.

Next we told Docker what command to run inside our new container:

/bin/echo 'Hello world'

When our container was launched Docker created a new Ubuntu 14.04environment and then executed the /bin/echo command inside it. We sawthe result on the command line:

Hello world

So what happened to our container after that? Well Docker containersonly run as long as the command you specify is active. Here, as soon asHello world was echoed, the container stopped.

An interactive container

Let’s try the docker run command again, this time specifying a newcommand to run in our container.

$ docker run -t -i ubuntu:14.04 /bin/bash
root@af8bae53bdd3:/#

Here we’ve again specified the docker run command and launched anubuntu:14.04 image. But we’ve also passed in two flags: -t and -i.The -t flag assigns a pseudo-tty or terminal inside our new containerand the -i flag allows us to make an interactive connection bygrabbing the standard in (STDIN) of the container.

We’ve also specified a new command for our container to run:/bin/bash. This will launch a Bash shell inside our container.

So now when our container is launched we can see that we’ve got acommand prompt inside it:

root@af8bae53bdd3:/#

Let’s try running some commands inside our container:

root@af8bae53bdd3:/# pwd
/
root@af8bae53bdd3:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

You can see we’ve run the pwd to show our current directory and cansee we’re in the / root directory. We’ve also done a directory listingof the root directory which shows us what looks like a typical Linuxfile system.

You can play around inside this container and when you’re done you canuse the exit command or enter Ctrl-D to finish.

root@af8bae53bdd3:/# exit

As with our previous container, once the Bash shell process hasfinished, the container is stopped.

A daemonized Hello world

Now a container that runs a command and then exits has some uses butit’s not overly helpful. Let’s create a container that runs as a daemon,like most of the applications we’re probably going to run with Docker.

Again we can do this with the docker run command:

$ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147

Wait, what? Where’s our “hello world” output? Let’s look at what we’ve run here.It should look pretty familiar. We ran docker run but this time wespecified a flag: -d. The -d flag tells Docker to run the containerand put it in the background, to daemonize it.

We also specified the same image: ubuntu:14.04.

Finally, we specified a command to run:

/bin/sh -c "while true; do echo hello world; sleep 1; done"

This is the (hello) world’s silliest daemon: a shell script that echoeshello world forever.

So why aren’t we seeing any hello world’s? Instead Docker has returneda really long string:

1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147

This really long string is called a container ID. It uniquelyidentifies a container so we can work with it.

Note:The container ID is a bit long and unwieldy. A bit later,we’ll see a shorter ID and ways to name our containers to makeworking with them easier.

We can use this container ID to see what’s happening with our hello world daemon.

Firstly let’s make sure our container is running. We cando that with the docker ps command. The docker ps command queriesthe Docker daemon for information about all the containers it knowsabout.

$ docker ps
CONTAINER ID  IMAGE         COMMAND               CREATED        STATUS       PORTS NAMES
1e5535038e28  ubuntu:14.04  /bin/sh -c 'while tr  2 minutes ago  Up 1 minute        insane_babbage

Here we can see our daemonized container. The docker ps has returned some usefulinformation about it, starting with a shorter variant of its container ID:1e5535038e28.

We can also see the image we used to build it, ubuntu:14.04, the command itis running, its status and an automatically assigned name,insane_babbage.

Note:Docker automatically generates names for any containers started.We’ll see how to specify your own names a bit later.

Okay, so we now know it’s running. But is it doing what we asked it to do? Tosee this we’re going to look inside the container using the docker logscommand. Let’s use the container name Docker assigned.

$ docker logs insane_babbage
hello world
hello world
hello world
. . .

The docker logs command looks inside the container and returns its standardoutput: in this case the output of our command hello world.

Awesome! Our daemon is working and we’ve just created our firstDockerized application!

Now we’ve established we can create our own containers let’s tidy upafter ourselves and stop our detached container. To do this we use thedocker stop command.

$ docker stop insane_babbage
insane_babbage

The docker stop command tells Docker to politely stop the runningcontainer. If it succeeds it will return the name of the container ithas just stopped.

Let’s check it worked with the docker ps command.

$ docker ps
CONTAINER ID  IMAGE         COMMAND               CREATED        STATUS       PORTS NAMES

Excellent. Our container has been stopped.

Next steps

So far, you launched your first containers using the docker run command. Youran an interactive container that ran in the foreground. You also ran adetached container that ran in the background. In the process you learnedabout several Docker commands:

  • docker ps - Lists containers.
  • docker logs - Shows us the standard output of a container.
  • docker stop - Stops running containers.

Now, you have the basis learn more about Docker and how to do some more advancedtasks. Go to “Run a simple application“ to actually build aweb application with the Docker client.

Docker Hello World Docker 允许你在容器内运行应用程序, 使用命令来在容器内运行一个应用程序。输出Hello worldDocker 的二进制执行文件。与前面的 docker 组合来运行一个容器。指定要运行的镜像,Docker 首先从本地主机上查找镜像是否存在,如果不存在,Docker 就会从镜像仓库 Docker Hub 下载公共镜像。在启动的容器里执行的命令。 阅读详情

相关推荐

Docker hello-world 命令深度解析:环境验证与故障排查指南

Docker 容器技术的核心起点并非构建镜像,而是验证运行时环境是否就绪。hello-world 作为官方设计的轻量级诊断镜像,本质是一个静态编译的 Go 程序,不依赖 shell、libc 或网络,专用于穿透 CLI→daemon→runtime 三层架构,完成安装可信度验证。其 1.84KB 极简体积和直接系统调用设计,消除了 glibc 版本、DNS 解析、权限配置等干扰变量,使报错信息可精准定位到 PATH 缺失、docker 组权限不足、daemon 未启动或 cgroup/v2 兼容性等底层问题

weixin_34080571的博客 484

1.Hello world in a container

Hello world in a container 1.第一个命令docker run $ docker run ubuntu /bin/echo 'hello world' hello world 在这个例子中 列表项目 docker run 运行了一个 container ubuntu 是一个镜像 ,docker 首先查看...

weixin_34329187的博客 105

docker run hello-world 原理与排错:Docker 环境验证黄金标准

Docker 容器技术的核心在于端到端的运行时闭环验证,而 docker run hello-world 正是这一闭环的最小可行诊断单元。它不仅检验 CLI 与 daemon 的通信能力,更串联镜像拉取、存储驱动、命名空间隔离、runc 运行时等底层机制,构成完整的容器生命周期验证链路。其轻量(2.4KB)、确定性(硬编码输出)、可观察性(逐阶段日志)三大特性,使其成为 Linux 权限配置、网络代理设置、镜像仓库连通性等高频问题的首道筛查工具。在 DevOps 实践与企业级容器部署中,该命令实质承担着环境

cumo7370的博客 442

Docker 入门之hello world

据说程序员写的第一个程序都是输出hello world,前2天在contos7中安装了docker,今天就输出个hello world 来入门吧。 docker允许在容器内部使用docker run 运行应用程序,我们可以使用docker run 来输出hello world。 一、检查下docker是否正确安装。 docker info //如果安装正确就会有很多docker的信息,如下图: docker-info 如果安装正确执行docker info 后就回输出如图很多信息,我.

wzs535131的博客 3133

Docker Hello World 验证全链路解析:从拉取到执行的四大关键环节

Docker 容器技术的核心在于运行时环境的可靠初始化与隔离执行机制。其本质是客户端通过 Unix Socket 与守护进程通信,调用 runc 运行时在 Linux namespace 和 cgroups 中启动进程。hello-world 镜像作为最小验证载体,以静态二进制、无依赖、瞬时退出为特征,精准暴露 Docker 安装链路上的四大关键环节:守护进程就绪性、镜像拉取通路、容器运行时加载、标准输出透传能力。它不仅是入门第一步,更是 DevOps 环境标准化、CI/CD 流水线稳定性及本地与生产环境一

weixin_30457465的博客 416

了解随机振动疲劳分析中 Ansys nCode DesignLife 的平均应力校正

通过选择静态环境,我们可以将其结果视为疲劳计算的平均应力,如图 3 所示,因此从静态偏移载荷工况中提取的平均应力用于转移预测雨流计数中所有循环的平均值。您可以通过观看下面的教学视频获得宝贵的见解,该视频将指导您完成利用 Ansys nCode DesignLife 分析平均应力对随机振动载荷下结构的影响的过程。它基于 R 比率或平均应力水平。另一方面,平均应力校正可以帮助消除平均应力的负面影响,提高结果的保真度。Ansys nCode 提供先进的平均应力校正技术,使工程师能够考虑平均应力对疲劳寿命的影响。

jkh920184196的博客 1518

Onyx编程语言入门:10分钟掌握核心语法与Hello World实例

Onyx是一种现代编程语言,提供简洁的语法和强大的功能。本文将帮助你快速入门Onyx,掌握核心语法并实现第一个Hello World程序。 ## 1. Onyx简介 Onyx是一个开源的编程语言项目,包含编译器和开发者工具链。它设计简洁,语法直观,适合各种编程任务。Onyx的核心优势在于其强大的标准库和灵活的类型系统,让开发者能够高效地构建各种应用。 ## 2. 环境准备 要开始使用Ony

gitblog_01185的博客 1024

实现单芯片2400bps 音频编解码方案

终于按照朋友的需求,帮他开发了一款单芯片集音频采集编码传送并接收解码播放功能的方案,交给快递公司邮寄给远在郑州的他.整个项目从开始定型到现在一个样机送出,整整花了1个月时间,感觉挺有成就感,挺有意思,工作是辛苦的,结果却是快乐的.现在将这中快乐的的心情与大家分享一下.    真个项目用一颗主控搞定,ARM9的,200KBytes 片内RAM,主频可以跑到300MHz,64pin LQFP封装

nyxsec的专栏 3682

008-Docker Hello World

通过运行,你可以快速验证 Docker 是否正确安装,并且了解 Docker 如何拉取镜像、创建容器并执行命令。这个简单的 "Hello World" 示例展示了 Docker 的基础操作,为你后续的学习打下基础。继续深入 Docker 的基本概念和操作,我们可以进一步探讨一些更复杂的 Docker 使用场景,以及如何操作容器和镜像。现在你已经了解了 Docker 的基本操作,包括如何管理容器、镜像、网络、数据卷等。

小宝哥Code的专栏 1390

具身智能与空天具身智能:从理论到实践的AIBOX技术革命

本文深入探讨了具身智能从理论到实践的发展,重点介绍了AIBOX技术如何作为边缘智能计算模块,为无人机、机器人等无人系统提供可进化的“大脑”。文章通过空天具身智能等应用场景,阐述了AIBOX在实现感知、决策、行动一体化闭环中的核心作用,并展望了其在协同智能与规模化部署中的未来挑战与机遇。

lll78的博客 765

0009 用VisualStudio设计Max工具

这次分享个独家专利^)^:在Visual Studio中设计3dsMax脚本工具界面。 某次做原型设计时,需求改来改去,实在懒得搞GUI;虽然也尝试在Axure RP里画原型,但还是Visual Studio更顺手,也更容易测试一些交互,就直接在VS里做了。后来突发奇想,想实验一把能否直接用到Max里去,结果没想到成功了,效果还挺好。发现了新大陆,记录一下。   开始: 在VS里新建W...

whwst的专栏 769

【docker】Hello World

CONTAINER ID: 容器 ID。IMAGE: 使用的镜像。COMMAND: 启动容器时运行的命令。CREATED: 容器的创建时间。STATUS: 容器状态。PORTS: 容器的端口信息和使用的连接类型(tcp\udp)。NAMES: 自动分配的容器名称。

一个写了10年bug的程序员日常笔记。 1995

TLV320AIC3204音频CODEC硬件设计与调试实战

本文深入解析了TLV320AIC3204音频CODEC的硬件设计与调试实战。文章从芯片功能定位入手,详细阐述了电源时钟设计、模拟输入电路等关键硬件设计要点,并提供了软件驱动配置与分层调试方法,帮助工程师有效规避常见陷阱,解决底噪、失真等典型音频调试问题。

zero1的博客 1122

内网环境安装docker并运行hello-world

一、环境说明 操作系统:CentOS7.4 docker版本:docker-ce-18.06.1.ce-3.el7.x86_64 安装包下载:https://download.youkuaiyun.com/download/zz_aiytag/11831396 安装包内的文件包括: docker安装包:docker-ce-18.06.1.ce-3.el7.x86_64.rpm 版本大于2.9的依赖包:con...

我的博客 3629

Coze智能体开发:搭建一个解析 PDF 文件的工作流

大模型本身并不具备文件读取和解析的能力,无法直接处理文件字节流。对于支持工具调用(Function calling)的模型,扣子提供插件功能来帮助大模型调用外部工具 API,拓展大模型的能力边界。扣子插件商店提供海量官方插件和第三方插件,例如链接读取插件可以将链接对应的文件内容解析为纯文本传递给大模型。

王国平的博客 2812

STM32CubeIDE开发环境搭建与GPIO控制实战

嵌入式开发中,MCU开发环境构建是软硬件协同的起点,其核心在于工具链选型、外设抽象层级与调试可靠性。HAL库作为ST官方标准硬件抽象层,通过统一接口屏蔽芯片差异,显著提升工程可移植性;而STM32CubeIDE则以图形化配置+自动生成代码的方式,实现‘配置即代码’的确定性开发范式。该组合在教学验证、原型迭代和中小规模量产中具备高性价比技术价值,广泛应用于智能传感、工业HMI及IoT终端等场景。本文聚焦STM32CubeIDE 1.15.0环境部署、MyST账户与固件包管理、ST-LINK驱动校验,以及基于H

weixin_33531560的博客 79

Docker使用(四) - Docker Hello World

Docker Hello World Docker Hello World运行交互式的容器启动容器(后台模式)停止容器 Docker Hello World Docker允许你在容器内运行应用程序,使用 docker run命令来在容器内运行应用程序 输出 hello world runoob@runoob:~$ docker run ubuntu:15.10 /bin/echo "Hello world" Hello world 各个参数解析: docker:docker的二进制执行文件 run:与

blue_lll的博客 568

[案例四] 智能填写属性工具(支持装配组件还有建模实体属性的批量创建、编辑)

本次案例主要是对上次导出自动导出BOM的一个前处理,要想导出属性,首先的有属性。于是本着学习的态度进行制作,可能有些功能有点别扭(支持装配环境下组件属性的批量填写,支持建模环境下的实体(不包括装配组件实体)——为了减负我把其过滤掉了,一般没人会往装配体里添加进行建模吧,但是不免有奇葩,哈哈哈)。

weixin_47753171的博客 1980

c++ helloworld_Docker 入门之hello world

据说程序员写的第一个程序都是输出hello world,前2天在contos7中安装了docker,今天就输出个hello world 来入门吧。 docker允许在容器内部使用docker run 运行应用程序,我们可以使用docker run 来输出hello world。一、检查下docker是否正确安装。docker info //如果安装正确就会有很多docker的信息,如下图...

weixin_39575410的博客 119

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

docker run hello-world Error response from daemon 解决办法

docker run hello-world Unable to find image 'hello-world:latest' locally docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://aut...

由入门到精通 1653

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Docker笔记-Docker Hello World

Docker笔记-Docker Hello World

YIYIYI 1172

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

上一篇: About Docker
下一篇: Run a simple application
screaming
博客等级 码龄19年 60粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值