4.docker基本使用

1.docker基本使用

1.1 镜像常用管理命令

[root@linux-node4 diff]# docker help                           # 查看docker帮助
[root@linux-node4 diff]# docker image --help                   # 查看 docker中 镜像相关帮助
[root@linux-node4 diff]# docker image ls                       # 查看当前所有镜像
[root@linux-node4 diff]# docker image inspect nginx            # 查看指定镜像(nginx镜像)详细信息
[root@linux-node4 diff]# docker pull nginx:1.14                # 下载指定版本镜像 nginx
[root@linux-node4 diff]# docker image rm nginx:1.14            # 删除nginx 1.14版本

1.2 docker创建容器常用命令

  • docker run 基本使用

  • root@dev:~# docker run -itd nginx
    root@dev:~# docker ps
    root@dev:~# docker rm -f e182a69f841d
  • docker run常用参数

-d   # 后台运行容器,并返回容器ID;
-i   # 以交互模式运行容器,通常与 -t 同时使用;
-t   # 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-P   # 随机端口映射,容器内部端口随机映射到主机的高端口
-p   # 指定端口映射,格式为:主机(宿主)端口:容器端口
--name="nginx-lb"   # 为容器指定一个名称;
--dns 8.8.8.8       # 指定容器使用的DNS服务器,默认和宿主一致;


docker使用


[root@linux-node4 diff]# docker container run -d --name web3 -e test=123456 -p 8800:80 -h webhostname --restart always nginx
-d                   # 后台启动nginx容器
--name web3          # 自定义容器名字(默认会是一段随机字符串)
-e test=123456       # 启动容器添加变量 test=123456 (echo $test)
-p 8800:80           # 宿主机的8800端口映射到docker容器的80端口中
-h webhostname       # docker容器主机名 (a300f394af88)
--restart always     # 宿主机重启自动拉起这个docker容器
nginx                # 使用这个nginx镜像启动容器
注:http://192.168.56.12:8800/     访问这个docker  nginx
[root@linux-node4 diff]# docker logs web                                 # 查看上面启动的web容器的日志
[root@linux-node4 diff]# docker exec -it web bash                        # 进入容器web
 
原文地址:https://www.cnblogs.com/gaodenghan/p/13957785.html