Docker 练习

#下载docker镜像
docker pull ubuntu

#查看镜像
docker images

#delete image
#docker rmi ubuntu

#启动镜像,并生成容器
docker run -it ubuntu bash
docker ps -a
### status is exited
#CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
#431dcb7be26a   ubuntu    "bash"    5 seconds ago   Exited (0) 2 seconds ago             pensive_mendel

#start container
docker start 431dcb7be26a
docker ps -a
###status is up
#CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES
#431dcb7be26a   ubuntu    "bash"    4 minutes ago   Up 9 seconds             pensive_mendel



#运行容器(431dcb7be26a)中的程序
docker exec -it 431dcb7be26a bash
root@431dcb7be26a:/# exit

docker ps -a
###
#CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS              PORTS     NAMES
#431dcb7be26a   ubuntu    "bash"    6 minutes ago   Up About a minute             pensive_mende

docker rm 431dcb7be26a
#failed because container was up
#Error response from daemon: You cannot remove a running container 431dcb7be26a5c4a0373a668b28698ab195a19f1f5aad77eddd4d5ed9b945f41. Stop the container before attempting removal or force remove

#stop 容器
docker stop 431dcb7be26a
docker ps -a
###status was exited
#CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                      PORTS     NAMES
#431dcb7be26a   ubuntu    "bash"    7 minutes ago   Exited (0) 18 seconds ago             pensive_mendel

#delete container
docker rm 431dcb7be26a
docker ps -a
#CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

cd workspace/container/

docker run -it -v /home/daizao/workspace/container:/mnt ubuntu bash
root@20c5d298c2e4:/# ls /mnt/
root@1b6e699ad545:/# cd /mnt/
root@20c5d298c2e4:/mnt# cd /opt/
root@20c5d298c2e4:/opt# cp /mnt/ncbi-blast-2.10.1+-x64-linux.tar.gz .
root@20c5d298c2e4:/opt# tar -zxf ncbi-blast-2.10.1+-x64-linux.tar.gz 
root@20c5d298c2e4:/opt# rm ncbi-blast-2.10.1+-x64-linux.tar.gz 
root@20c5d298c2e4:/opt# cp ncbi-blast-2.10.1+/bin/* /usr/local/bin/
root@20c5d298c2e4:/opt# exit

#显示所有容器
docker ps -a
#CONTAINER ID   IMAGE     COMMAND   CREATED              STATUS                      PORTS     NAMES
#1b6e699ad545   ubuntu    "bash"    About a minute ago   Exited (0) 18 seconds ago             vibrant_jang

#put 1b6e699ad545's container to blast image
docker commit 1b6e699ad545 blast
docker images
#REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
#blast        latest    35b6b4b4411a   54 seconds ago   1.43GB
#ubuntu       latest    26b77e58432b   15 hours ago     72.9MB
#create blast image

#run image
docker run blast blastp -h

docker ps -a
#CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
#da74854199c5   blast     "blastp -h"   6 seconds ago   Exited (0) 5 seconds ago             unruffled_saha
#1b6e699ad545   ubuntu    "bash"        7 minutes ago   Exited (0) 6 minutes ago             vibrant_jang
#出现blast和ubuntu container,因为之前创建blast,启用了ubuntu镜像,导致出现ubuntu容器


#将blast image 保存成本地文件
docker save -o blast.tar blast
ls #生成一个blast.tar 文件
docker images
docker ps -a
#CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
#da74854199c5   blast     "blastp -h"   4 minutes ago    Exited (0) 4 minutes ago             unruffled_saha
#1b6e699ad545   ubuntu    "bash"        11 minutes ago   Exited (0) 9 minutes ago             vibrant_jang
docker stop da74854199c5 #停止启用blast镜像的容器
docker rm da74854199c5 #有时候已经停止了容器,但无法删除镜像,所以直接删除容器,在删除镜像
docker ps -a
#CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS                      PORTS     NAMES
#1b6e699ad545   ubuntu    "bash"    13 minutes ago   Exited (0) 11 minutes ago             vibrant_jang
#说明容器da74854199c5彻底停止
docker rmi blast

#加载本地docker文件,生成镜像
docker load -i blast.tar

docker run blast blastp -h
docker ps -a
#CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                      PORTS     NAMES
#07dac63e27c1   blast     "blastp -h"   12 seconds ago   Exited (0) 8 seconds ago              serene_einstein
#1b6e699ad545   ubuntu    "bash"        16 minutes ago   Exited (0) 14 minutes ago             vibrant_jang
#镜像一旦启动,便会生成一个container
docker rm 07dac63e27c1
docker ps -a
#CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS                      PORTS     NAMES
#1b6e699ad545   ubuntu    "bash"    17 minutes ago   Exited (0) 16 minutes ago             vibrant_jang

#delete image
docker rmi blast
docker images
#REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
#ubuntu       latest    26b77e58432b   15 hours ago   72.9MB
此条目发表在Container分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud