zoukankan      html  css  js  c++  java
  • 启动docker某个image(镜像)的已经关闭的container(容器)

    1.创建一个后台运行 ubuntu 容器

    root@haima-PC:/home/haima/Desktop# docker run -d --name ubuntu-lnmp ubuntu
    bf243aabfe110f1aed17a6298c5dbe33df2d023e18fa2f1e1cdb9682d289f710
    

    2.进入容器

    root@haima-PC:/home/haima/Desktop# docker exec -it ubuntu-lnmp /bin/bash
    root@bf243aabfe11:/# cd /home 
    root@bf243aabfe11:/home# ls
    root@bf243aabfe11:/home# mkdir test
    root@bf243aabfe11:/home# ls
    test
    

    3.退出容器 exit

    4.查看所有的container,包括运行中的,以及未运行的或者说是沉睡镜像,则运行:

    docker ps -a

    root@haima-PC:/home/haima/Desktop# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    bf243aabfe11        ubuntu              "/bin/bash"         5 minutes ago       Up 5 minutes                            ubuntu-lnmp
    d4d18c2d2025        centos:v4           "/bin/bash"         2 months ago        Up 3 hours                              centos_env
    

    5.运行已经关闭的容器

    root@haima-PC:/home/haima/Desktop# docker start ubuntu-lnmp
    ubuntu-lnmp
    

    其中“ubuntu-lnmp”是容器的名称。这里会后台运行容器,进入容器再退出后,容器也不会关闭

    6.进入容器

    root@haima-PC:/home/haima/Desktop# docker exec -it ubuntu-lnmp /bin/bash
    root@b8cc973c3d4d:/# 
    
    • ubuntu-lnmp:要启动的container的名称
    • /bin/bash:在container中启动一个bash shell

    7. 退出container容器

    输入:

    exit

    或者按键:

    Ctrl + D

    8.在容器里更改的文件退出后,还会在历史记录的这次运行的容器里,只要下次再运行这个容器,就可以找到之前操作的资料.

  • 相关阅读:
    hdu3487 Play with Chain
    poj3481
    [HNOI2002]营业额统计
    poj3468 A Simple Problem with Integers
    [NOI2004]郁闷的出纳员
    UVa1308 LA2572
    20130620
    poj3580
    20130618
    C++类模版学习笔记
  • 原文地址:https://www.cnblogs.com/haima/p/12287394.html
Copyright © 2011-2022 走看看