赞
踩
两种启动方式:
docker run
;hello world
,终止容器:docker run ubuntu:18.04 /bin/echo "hello world"
noamanelson@noamanelson-Virtual-Machine:~$ docker run ubuntu:18.04 /bin/echo "hello world"
hello world
bash
,进行用户交互操作:docker run -t -i ubuntu:18.04 /bin/bash
noamanelson@noamanelson-Virtual-Machine:~$ docker run -t -i ubuntu:18.04 /bin/bash
root@b0d76f1a813b:/#
root@b0d76f1a813b:/#
root@b0d76f1a813b:/#
参数 | 说明 |
---|---|
-t | 让docker 分配一个伪终端并绑定到容器的标准输入上 |
-i | 让容器的标准输入保持打开 |
docker container start
;-d
参数即可;docker run -d ubuntu:18.04 /bin/echo "sdsdsd"
noamanelson@noamanelson-Virtual-Machine:~$ docker run -d ubuntu:18.04 /bin/echo "sdsdsd"
056508ab9ff61b07a468418bd281b03ee023abbbc514f7a7392d3a59d18ac0dc
noamanelson@noamanelson-Virtual-Machine:~$
docker logs
:noamanelson@noamanelson-Virtual-Machine:~$ docker logs 056508ab9ff61b07a468418bd281b03ee023abbbc514f7a7392d3a59d18ac0dc
sdsdsd
noamanelson@noamanelson-Virtual-Machine:~$
docker container ls
;noamanelson@noamanelson-Virtual-Machine:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
04489fec9611 ubuntu:18.04 "/bin/bash" 12 seconds ago Up 9 seconds modest_nobel
docker container stop
;启动:docker container start
重启:docker container restart
docker run -t -i ubuntu:18.04 /bin/bash
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0a9622dfb8f8 ubuntu:18.04 "/bin/bash" 51 seconds ago Up 48 seconds exciting_hodgkin
docker container stop 0a9622dfb8f8
noamanelson@noamanelson-Virtual-Machine:~$ docker run -dit ubuntu:18.04
f28907e275433bc54d18c9e791e2d593e0a3b2d55562932a025022ae2e515532
noamanelson@noamanelson-Virtual-Machine:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e3931186d9e8 ubuntu:18.04 "/bin/bash" 39 seconds ago Up 36 seconds distracted_hermann
noamanelson@noamanelson-Virtual-Machine:~$ docker attach e393
root@e3931186d9e8:/#
root@e3931186d9e8:/#
root@e3931186d9e8:/#
root@e3931186d9e8:/#
root@e3931186d9e8:/#
docker attach
进入容器后,会导致容器停止。docker attach
区别是不会导致容器停止,建议使用这个方式;noamanelson@noamanelson-Virtual-Machine:~$ docker run -dit ubuntu:18.04
714618edc1103ff02eda2b2c5f33e4ff48ac15efc1aeda0a9087d6d63b124dbb
noamanelson@noamanelson-Virtual-Machine:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
714618edc110 ubuntu:18.04 "/bin/bash" 4 seconds ago Up 2 seconds jovial_brahmagupta
noamanelson@noamanelson-Virtual-Machine:~$ docker exec -i 7146
"docker exec" requires at least 2 arguments.
See 'docker exec --help'.
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Execute a command in a running container
noamanelson@noamanelson-Virtual-Machine:~$ docker exec -i 7146 bash
ls
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
docker attach
类似了:noamanelson@noamanelson-Virtual-Machine:~$ docker exec -it 7146 bash
root@714618edc110:/#
root@714618edc110:/#
root@714618edc110:/#
root@714618edc110:/#
root@714618edc110:/#
docker export
; docker import
;docker container rm
;noamanelson@noamanelson-Virtual-Machine:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
714618edc110 ubuntu:18.04 "/bin/bash" 13 minutes ago Up 13 minutes jovial_brahmagupta
noamanelson@noamanelson-Virtual-Machine:~$ docker container rm jovial_brahmagupta
Error response from daemon: You cannot remove a running container 714618edc1103ff02eda2b2c5f33e4ff48ac15efc1aeda0a9087d6d63b124dbb. Stop the container before attempting removal or force remove
noamanelson@noamanelson-Virtual-Machine:~$
-f
参数:docker container prune
:使用
docker container ls -a
可以查看终止的容器
使用清除命令:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。