一. 对Docker的理解
Docker是容器(container)技术的一种实现。
Docker的镜像(image)被加载以后,就形成了一个容器(container)
- image id 与 docker id
image id 是静态的,与 image对应
一个image可以被加载多次,每一个加载的image都会开成一个container, 有对应的container id.
二. Docker操作
参见文章 Docker 入门教程
-
Docker镜像的获取
-
查询宿主机(本机)里有哪些image:
docker image
-
生成容器:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
options:
–name=“容器新名字” 为容器指定一个名称;
-d: 后台运行容器并返回容器ID,也即启动守护式容器(后台运行);
-i:以交互模式运行容器,通常与 -t 同时使用;
-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;
run 命令是生成container, 每run 一次都会生成一个新的容器。 -
启动容器:
docker container start [OPTIONS] CONTAINER [CONTAINER...]
生成的窗口应该是被存储了,重启宿主机后,仍能找到这些容器并启动。
以下container清单是重启以后查看的
-
查询有哪些容器在运行中
docker ps [OPTIONS]
Options:
-a, --all Show all containers (default shows just running)
-f, --filter filter Filter output based on conditions provided
–format string Pretty-print containers using a Go template
-n, --last int Show n last created containers (includes all states) (default -1)
-l, --latest Show the latest created container (includes all states)
–no-trunc Don’t truncate output
-q, --quiet Only display container IDs
-s, --size Display total file sizes
-
进入容器
docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]
Options:
-d, --detach Detached mode: run command in the background
–detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
–env-file list Read in a file of environment variables
-i, --interactive Keep STDIN open even if not attached
–privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
注意: 如果在挂载image 时用–name=‘container name’ 参数指定了docker name,那么这个命令就可以指定的container name, 否则就只能使用container ID.
-
停止容器
docker container kill [OPTIONS] CONTAINER [CONTAINER...]
-
在窗口内查看容器的ip地址:
hostname -i
这其实是Linux的命令
每一个容器都会有一个内网IP, 参见文章 如何获取 Docker 容器的 IP 地址 -
D
-
D