【Docker】命令 run

参考教程:https://docs.docker.com/engine/reference/commandline/run/

环境

  1. virtual box 6.1
  2. centos 7.8
  3. docker 19.03

命令格式

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

使用 run 命令可以直接从镜像启动一个容器,如果镜像在本地不存在,会自动到 registry 中去获取。

命令选项

由于命令选项有很多,下面选择几个常用的进行学习。

名称 默认值 描述
--interactive , -i 标准输入
--tty , -t 分配一个伪终端
--detach , -d 后台运行容器
--publish , -p 映射容器的端口到宿主机
--publish-all , -P 映射容器的所有端口到宿主机的随机端口

示例

前台运行容器

[root@master ~]# docker run -it busybox /bin/sh
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ # ps -ef
PID   USER     TIME  COMMAND
    1 root      0:00 /bin/sh
    7 root      0:00 ps -ef
/ #

启动后台容器

[root@master ~]# docker run -d -p8080:80 nginx
b82ba0c69740581c68cb602f66edb38d7327f63f9f47b0d6002e3763af70d481
[root@master ~]# curl 192.168.56.102:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

运行 nginx

总结

介绍了 run 命令的使用,在运行容器时,可以指定各种参数。

posted @   jiangbo4444  阅读(144)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示