Docker学习
介绍
Docker是镜像管理工具,通过run命令生成各个Container(容器)
镜像管理
查看镜像列表
docker image ls
搜索镜像
docker search 名称
拉取镜像
docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
eg:
$ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
92dc2a97ff99: Pull complete
be13a9d27eb8: Pull complete
c8299583700a: Pull complete
Digest: sha256:4bc3ae6596938cb0d9e5ac51a1152ec9dcac2a1c50829c74abd9c4361e321b26
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
删除镜像
docker image rm [选项] <镜像1> [<镜像2> ...]
名称通常使用长ID
,ID前三位
,仓库名+tag
进行删除
eg
admin@AliServer:~/code$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest d13c942271d6 4 weeks ago 72.8MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
docker image rm ubuntu:latest
docker image rm d13
docker image rm d13c942271d6
docker image rm $(docker image ls -q ubuntu) #删除所有ubuntu的镜像
容器管理
查看所有容器
docker ps -a
eg
admin@AliServer:~/code$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c0615f6b43e ubuntu:latest "/bin/sh -c 'while t…" 59 minutes ago Up 59 minutes dazzling_mcclintock
4c6fcb36551c ubuntu:latest "/bin/sh -c 'while t…" About an hour ago Exited (130) About an hour ago funny_herschel
启动容器
docker run -it --rm ubuntu:18.04 bash
#以bash形式进入镜像,并在停止后删除容器
docker container start [ContainterID]
docker run ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
`docker run -d ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
停止容器
docker container stop [ContainterID]
查看容器日志
docker container logs [ContainterID]
进入容器
docker attach [ContainterID]