默认分类

Docker 容器常用操作以及迁移

一:下载镜像操作

docker pull NAME:TAG

二:查看已经下载好的镜像

docker images

三:使用已经下载好的镜像创建container

docker create -p 80:80 --name typecho 80x86/typecho
-p 参数为把docker容器的80端口映射到虚拟机 --name 参数是给新建立的containe的名字 80x86/typecho为docker images镜像名

四:启动,停止,重启container操作

1:docker ps -a 查看所有创建的container,不加参数-a是查看状态为运行的container  
root@iZj6ce8gtknecijg0zq0axZ:~# docker ps -a
CONTAINER ID   IMAGE            COMMAND                  CREATED        STATUS                    PORTS                               NAMES
070e21d46822   80x86/typecho2   "/entrypoint.sh /app…"   14 hours ago   Up 14 hours (healthy)     0.0.0.0:80->80/tcp, :::80->80/tcp   typeecho
909dcf29bcaf   tt:latest        "/bin/ls /app/"          14 hours ago   Exited (0) 14 hours ago                                       brave_pascal
3a2dc997fcb8   tt:latest        "/bin/ls /app/u"         14 hours ago   Exited (1) 14 hours ago                                       agitated_nobel
108ec7d88258   tt:latest        "/bin/ls /app/usr"       14 hours ago   Exited (0) 14 hours ago                                       gifted_shaw
a40e2fde66b7   tt:latest        "/bin/ls"                14 hours ago   Exited (0) 14 hours ago                                       exciting_hodgkin
e6da4fa044b7   tt:latest        "/bin/ash"               14 hours ago   Exited (0) 14 hours ago                                       optimistic_easley
19af990997e2   tt:latest        "bin"                    14 hours ago   Created                                                       happy_lehmann
2:查看docker ps -a 查看需要运行的container id,使用docker start container id ,docker stop container id,docker restart container id,启动,停止,和重启container

五:docker exec 进入container

docker exec -it container id /bin/ash
-it 参数使用交互式tty操作,不然不能使用shell进入

六:docker inspect 查看镜像挂载的数据卷

oot@VM-0-8-ubuntu:~#  docker inspect --format=’{{.Mounts}}’ nostalgic_brahmagupta
’[{volume 8d3d003f6942018572c5ea1ab857bed54c897036e363116cfc3eda32f3d93c47 /var/lib/docker/volumes/8d3d003f6942018572c5ea1ab857bed54c897036e363116cfc3eda32f3d93c47/_data /data local  true }]’

七:运行中的container迁移

1:docker ps 查看CONTAINER ID

CONTAINER ID   IMAGE            COMMAND                  CREATED        STATUS                  PORTS                               NAMES
070e21d46822   80x86/typecho2   "/entrypoint.sh /app…"   14 hours ago   Up 14 hours (healthy)   0.0.0.0:80->80/tcp, :::80->80/tcp   typeecho

2:docker commit 根据CONTAINER ID创建新的Docker images

1:进入CONTAINER将/data数据打包到根目录,docker commit操作默认不会备份CONTAINER的数据目录,数据目录在/data/,docker镜像的用户数据一般通过软链接到/data目录


root@iZj6ce8gtknecijg0zq0axZ:~# docker exec -it 070e21d46822 /bin/ash
/app # ls -lh
total 8396
drwxr-sr-x    1 www      www         4.0K Jan 24 19:39 2023-01-24
-rw-r--r--    1 www      www        14.6K May  8  2019 LICENSE.txt
-rw-r--r--    1 www      www          318 May  8  2019 README.md
drwxr-xr-x    1 www      www         4.0K May  8  2019 admin
-rw-r--r--    1 www      www         2.1K May  8  2019 changelog.txt
lrwxrwxrwx    1 www      www           20 May 12  2020 config.inc.php -> /data/config.inc.php
-rw-r--r--    1 www      www         8.1M Jan 24 21:00 data.tar
-rw-r--r--    1 www      www        15.0K May  9  2019 favicon.ico
-rw-r--r--    1 www      www          721 May  8  2019 index.php
drwxr-xr-x    1 www      www         4.0K May  8  2019 install
-rw-r--r--    1 www      www        47.8K May  9  2019 install.php
drwxr-xr-x    1 www      www         4.0K May  8  2019 tools
lrwxrwxrwx    1 www      www            5 May 12  2020 usr -> /data
drwxr-xr-x    1 www      www         4.0K May  8  2019 var

2:打包/data目录到CONTAINER 根目录,这样操作docker commit操作后可以把/data/文件也打包
/ # cd /data
/data # ls
5ebabdc562747.db  config.inc.php    data.tar          log               plugins           themes            uploads
/data # tar czvf /data.tar *
5ebabdc562747.db
config.inc.php
tar: data.tar: file is the archive; skipping
log/
log/php7/
log/php7/fpm-php.www.err.log
log/nginx/
log/nginx/error.log
log/nginx/access.log
plugins/
plugins/Pio/
plugins/Pio/models/
plugins/Pio/models/pio/
plugins/Pio/models/pio/textures/
plugins/Pio/models/pio/textures/school-costume.png
plugins/Pio/models/pio/textures/default-costume.png
plugins/Pio/models/pio/textures/pajamas-costume.png
plugins/Pio/models/pio/model.json
plugins/Pio/models/pio/model.moc
plugins/Pio/models/pio/motions/
plugins/Pio/models/pio/motions/Breath Dere3.mtn
plugins/Pio/models/pio/motions/Touch Dere3.mtn
plugins/Pio/models/pio/motions/Touch Dere4.mtn
plugins/Pio/models/pio/motions/Touch1.mtn
plugins/Pio/models/pio/motions/Sleeping.mtn
plugins/Pio/models/pio/motions/Breath1.mtn
plugins/Pio/models/pio/motions/Sukebei1.mtn
plugins/Pio/models/pio/motions/Touch2.mtn
plugins/Pio/models/pio/motions/Touch Dere6.mtn
plugins/Pio/models/pio/motions/Sukebei3.mtn



3:docker commit -p 070e21d46822  80x86/typecho-bak
sha256:2fc4f45bb06b9b1baa02f9f326601223970453a40092121fa06375ba2e6dc76f
-p 参数为CONTAINER ID 80x86/typecho-bak是新建立的镜像,通过docker images 可以看到

3:docker images 查看刚刚生成的Images

root@iZj6ce8gtknecijg0zq0axZ:~# docker images
REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
80x86/typecho2-bak   latest    2fc4f45bb06b   4 seconds ago   79.3MB
80x86/typecho2       latest    33a92425a442   14 hours ago    66.6MB

4:docker save 保存images为tar文件

docker save -o typecho-bak.tar 80x86/typecho2-bak
使用80x86/typecho2-bak -o 输出为typecho-bak.tar 
使用tar 压缩以减少网络传输时间 tar czvf typecho-bak.lz.tar typecho-bak.tar

5:使用http,ftp等工具将备份的typecho-bak.lz.tar下载到新服务器

6:docker load 加载刚刚备份的镜像

已经压缩的typecho.lz.tar 使用tar xvf typecho.lz.tar 先解压
root@iZj6ce8gtknecijg0zq0axZ:~# docker load  -i typecho.tar 
6023595b7077: Loading layer [==================================================>]  5.057MB/5.057MB
The image 80x86/typecho2:latest already exists, renaming the old one with ID sha256:33a92425a442665688283bbb95efa96403ba89cf1e1bc8d9f10de7d87607c782 to empty string
Loaded image: 80x86/typecho2:latest
root@iZj6ce8gtknecijg0zq0axZ:~# docker images
REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
80x86/typecho2-bak   latest    2fc4f45bb06b   8 minutes ago   79.3MB
80x86/typecho2       latest    e61c1bcbda3c   16 hours ago    58.1MB

7:docker create创建container,docker ps -a 查看container id,docker start container id运行container,docker exec 进入container 解压data.tar到/data目录下,还原用户数据

root@iZj6ce8gtknecijg0zq0axZ:~# docker create -p 88:80 --name ty 80x86/typecho2-bak
ac720985a5ae023f5d9785a9649875687f16539aee695ad13b1e5fedc2290939
root@iZj6ce8gtknecijg0zq0axZ:~# docker exec -it 7edc3b095367 /bin/sh
/app # cd /
/ # ls
app            bin            data.tar       entrypoint.sh  home           lib            media          opt            root           sbin           sys            usr
app-init.sh    data           dev            etc            inject.sh      libexec        mnt            proc           run            srv            tmp            var
/ # cd data
/data # tar xvf /data.tar 
5ebabdc562747.db
config.inc.php
data.tar
log/
log/php7/
log/php7/fpm-php.www.err.log
log/nginx/
log/nginx/error.log
log/nginx/access.log
plugins/
plugins/Pio/
plugins/Pio/models/
plugins/Pio/models/pio/
plugins/Pio/models/pio/textures/

回复

  1. lhrwpdxrga lhrwpdxrga
    Sogo 10

    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com

  2. xdneqemesn xdneqemesn
    Sogo 10

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

  3. 华纳公司开户注册指南?(▲18288362750?《?微信STS5099? 】【╃q 2704132802╃】

  4. 华纳圣淘沙开户步骤详解(183-8890-9465—?薇-STS5099【6011643】

    华纳圣淘沙公司开户流程全解析(183-8890-9465—?薇-STS5099【6011643】
    华纳圣淘沙公司账户注册指南(183-8890-9465—?薇-STS5099【6011643】
    新手如何开通华纳圣淘沙公司账户(183-8890-9465—?薇-STS5099【6011643】
    华纳圣淘沙企业开户标准流程(183-8890-9465—?薇-STS5099【6011643】
    华纳圣淘沙公司开户:从零到一(183-8890-9465—?薇-STS5099【6011643】
    官方指南:华纳圣淘沙公司开户流程(183-8890-9465—?薇-STS5099【6011643】
    华纳圣淘沙公司开户流程说明书(183-8890-9465—?薇-STS5099【6011643】

  5. a0tj.cn a0tj.cn
    Sogo 10

    成都中和耍妹一般晚上去哪个地方a0cc.cn

This is just a placeholder img.