docker镜像管理
1.查看镜像列表
# Management Commands $ docker image ls
///查看 ubuntu 仓库的镜像:
$ docker image ls ubuntu
2.查看镜像信息
# Management Commands $ docker image inspect ubuntu
3.搜索镜像
$ docker search ubuntu
4.拉取镜像
# Management Commands $ docker image pull [OPTIONS] NAME[:TAG|@DIGEST]
$ docker image pull ubuntu:14.04
5.构建镜像
# Management Commands $ docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
# 使用 run 创建运行一个新命令
$ docker container run \
--name shiyanlou001 \
-it busybox /bin/sh
# 在运行的容器中创建两个文件,test1 和 test2
touch test1 test2
# 使用 ctrl + p 及 ctrl+q 键退出
# 使用提交命令,提交容器 shiyanlou001 的修改到镜像 busybox:test 中
$ docker container commit shiyanlou001 busybox:test
# 查看通过提交创建的镜像
$ docker image ls busybox
docker image build [OPTIONS] PATH | URL
# 指定基础镜像
FROM ubuntu:14.04
# 维护者信息
MAINTAINER shiyanlou/shiyanlou001@simplecloud.cn
# 镜像操作命令
RUN \
apt-get -yqq update && \
apt-get install -yqq apache2
# 容器启动命令
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
///创建一个空目录,并在其中编辑 Dockerfile 文件,并基于此构建一个新的镜像
# 首先创建目录并切换目录
$ mkdir /home/shiyanlou/test1 && cd /home/shiyanlou/test1
# 编辑 Dockerfile 文件,默认文件名为 `Dockerfile`,也可以使用其它值,使用其它值需要在构建时通过 `-f` 参数指定,这里我们使用默认值。并在其中添加上述示例的内容
$ vim Dockerfile
# 使用 build 命令,`-t` 参数指定新的镜像
$ docker image build -t shiyanlou:1.0 .
///使用该镜像启动一个容器来运行 apache 服务
# 使用 -p 参数将本机的 8000 端口映射到容器中的 80 端口上。
$ docker container run \
-d -p 8000:80 \
--restart=always \
--name shiyanlou002 shiyanlou:1.0
6.删除镜像
Management Commands
$ docker image rm ubuntu:latest