1. 启动Docker服务
    $ serivce docker start
    
  2. 创建一个Docker容器
    $ docker run -i -t centos /bin/bash
    

    Docker首先检测本地是否有centos镜像,如果没有,链接官方的Docker Hub拉取保存至本地宿主机中。创建出的容器拥有自己的网络,ip,以及一个用来和宿主主机进行通讯的桥接网络接口。最后,我们告诉Docker在新容器 中要运行什么命令。同时,Docker帮我们自动生成一个新容器的ID

  3. 列出所有Docker容器
    $ docker ps -a
    $ docker ps -l
    
  4. 容器命名
    $ docker run --name firstdocker -i -t centos /bin/bash
    
  5. 重启已经停止的容器
    $ docker start firstdocker
    //或者
    $ docker start $ID
    
  6. 附着到容器上Docker容器重新启动的时候,会沿用docker run命令时指定的参数来运行,因此我们容器重新启动后会运行一个交互式shell。此外,我们也可以用docker attach命令,重新附着到该容器的绘画上
    $ docker attach firstdocker
    //或者
    $ docker attach $ID 
    
  7. 创建守护式容器
    $ docker run --name second_docker -d centos /bin/sh -c "while true; 
     do echo hello world; sleep 1; done"
    

    容器内部输出

    $ docker logs second_docker
    
    hello world
    hello world
    hello world
    

    跟踪日志

    $ docker logs -f second_docker
    

    我们也可以跟踪容器日志的某一片段,和之前类似,只需要在tail命令后加入-f –lines标记即可,例如获取日志最后10行的内容

    $ docker logs --tail 10 second_docker
    

    跟踪容器的最新日志而不读取整个日志文件

    $ docker logs --tail 0 -f second_docker
    

    也可以加入-t标记为每条日志增加时间戳

    $ docker logs -ft second_docker
    
  8. 查看容器内的进程
    $ docker top second_docker
    
  9. 在容器内部运行进程
    $ docker exec -d second_docker touch /etc/demofile
    $ docker exec -t -i second_docker /bin/bash
    

    -d表示在后台运行,-t创建一个TTY,-i捕捉STDIN

  10. 停止和删除容器
    $ docker stop second_docker
    $ docker stop $ID
    //stop可以替换成kill
    
    $ docker rm second_docker
    $ docker rm $ID
    $ docker rm 'docker ps -a -q'                         //删除所有容器
    
  11. 自动重启容器
    $ docker run --restart=always --name third_docker centos /bin/bash
    

    –restart标志会检查容器的退出代码,并根据此来决定是否要重启容器。默认Docker不会重启。此处标记 –restart=always,无论容器的退出代码是什么,Docker都会自动重启该容器,除了always,我们还可以将这个标记设置为on- failure,这样,只有当容器退出代码为非0值得时候,才会自动重启,另外,on-failure还接受一个可选的重启次数参数,如

    $ --restart=on-faulure:5
    
  12. 深入容器
    $ docker inspect third_docker
    $ docker inspect --format='{{.State.Running}}' third_docker
    
    $ docker inspect --format='{{.NetworkSetting.IPAddress}}' \ 
     first_docker second_docker third_docker
    

    –format或者-f标记远非看上去那么简单,该标记实际上支持完整的Go语言模板。 除了查看容器,你还可以通过浏览本地/var/lib/docker目录来深入了解Docker工作原理,该目录存放着Docker镜像,容器以及容器配置,所有的容器都保存在/var/lib/docker/containers目录下。

分类: Docker

24 条评论

https://clients1.google.com.ua · 2026-08-21 01:35

References:

Politia rutiera https://clients1.google.com.ua

http://maps.google.com.bn/ · 2026-08-21 05:12

References:

Online roulette play roulette and receive $1500 http://maps.google.com.bn/

www.chiffandfipple.com · 2026-08-22 07:50

References:

Great canadian casino http://www.chiffandfipple.com

https://forums.indigostack.app · 2026-08-22 23:08

References:

Rushmore casino https://forums.indigostack.app

paper-auk.pikapod.net · 2026-08-22 23:09

References:

Hobart casino paper-auk.pikapod.net

tiger777mx · 2026-09-02 00:36

[4971]tiger777mx Login Oficial | Slots en Línea y Depósitos OXXO,Entra a tiger777mx y descubre las mejores slots en línea. Descarga la APK oficial y realiza depósitos rápidos con OXXO para empezar a jugar ahora mismo. visit: tiger777mx

pkpakgaming · 2026-09-19 19:36

I love how this platform brings the best cricket and casino action together in one place. Everything feels secure and the customer service really listens to players. It is rare to find a site that cares this much about its community. Come see for yourself pkpakgaming

https://vseapsny.ru/user/yarnpilot7/ · 2026-09-22 05:23

References:

Online casino sofortüberweisung 2026 https://vseapsny.ru/user/yarnpilot7/

fe8bet · 2026-09-22 06:40

[6502]Fe8bet | Link vào chính thức và hướng dẫn chơi baccarat,Truy cập fe8bet qua link vào chính thức để tải app fe8bet nhanh chóng. Khám phá mẹo quay hũ dễ nổ và nạp tiền casino qua momo tiện lợi. Tham gia ngay! visit: fe8bet

codimd.syssec.org · 2026-09-23 01:33

References:

Sofort Casino Mindesteinzahlung codimd.syssec.org

higgins-daugaard.thoughtlanes.net · 2026-09-23 01:39

References:

Casino sofortüberweisung klarna higgins-daugaard.thoughtlanes.net

http://www.qilurexian.net/?241578 · 2026-09-23 04:05

References:

Online casino mit sofortüberweisung auszahlung http://www.qilurexian.net/?241578

xbymw.com · 2026-09-23 04:11

References:

Casino ohne mindesteinzahlung sofortüberweisung xbymw.com

Echtgeld Casino mit Sofort · 2026-09-23 06:29

References:

Sofort casinos auszahlung Echtgeld Casino mit Sofort

https://dok.kompot.si · 2026-09-23 07:12

References:

How to play pokies with payid https://dok.kompot.si

https://test-sida.noads.biz/?462570 · 2026-09-23 08:01

References:

Spielothek sofortüberweisung klarna https://test-sida.noads.biz/?462570

ua-ds.com.ua · 2026-09-23 09:31

References:

Low deposit payid pokies ua-ds.com.ua

spielhalle mit sofortüberweisung · 2026-09-23 10:40

References:

Sofort Casinos Deutschland spielhalle mit sofortüberweisung

http://www.viewtool.com · 2026-09-23 10:59

References:

Online casino sofortüberweisung limit http://www.viewtool.com

winnipegasians.com · 2026-09-23 16:39

References:

Casino Sofort Einzahlung https://winnipegasians.com/home.php?mod=space&uid=168713

www.wulanbatuoguojitongcheng.com · 2026-09-23 20:31

References:

Wie funktioniert Sofortüberweisung im Casino https://www.wulanbatuoguojitongcheng.com/home.php?mod=space&uid=1069070

http://www.bzsbs.cn/ · 2026-09-24 00:09

References:

Online casino startguthaben sofort http://www.bzsbs.cn/home.php?mod=space&uid=1320544

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注