Docker的一些记录,学完就忘

本文详细介绍了Docker的安装过程,包括卸载旧版本、设置镜像仓库、安装社区版和企业版。接着讲解了Docker的基本操作,如运行hello-world、查看和下载镜像、删除镜像、启动和停止容器、容器命令以及日志查看。还提到了阿里云镜像加速,并展示了如何使用Docker运行Nginx服务。
摘要由CSDN通过智能技术生成
docker安装

在docker帮助文档有安装教程 https://docs.docker.com/

1.如果之前有安装过docker需要卸载完后再安装新的

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2.需要的安装包

 sudo yum install -y yum-utils

3.设置镜像仓库

 sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo 
    # 默认是从国外下载的
    
     sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    # 推荐使用阿里云的

4.安装docker docker-ce 社区版 ee 企业版

yum install docker-ce docker-ce-cli containerd.io
5.启动docker
systemctl start docker

查看docker版本
docker version

在这里插入图片描述

6.hello-world

docker run hello-world

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-kWrH8P0l-1637583769169)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211014200108669.png)]

7.查看一下下载的hello-world镜像

[root@iZuf6dcdal1ed3wkay21z4Z /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   2 weeks ago   13.3kB

卸载docker

1.卸载依赖
yum remove docker-ce docker-ce-cli containerd.io

2.删除资源
rm -rf /var/lib/docker
阿里云镜像加速

在这里插入图片描述
在这里插入图片描述

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://eq0r60ij.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker
Run的流程和docker原理

在这里插入图片描述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IsLN1Cf2-1637583769174)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211021191830392.png)]

Docker为什么比VM快?

  1. Docker有着比虚拟机更少的抽象层。
  2. docker利用的是宿主机的内核,vm需要是Guest OS。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GB3lFSYW-1637583769175)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211021192130447.png)]

所以说,新建一个容器的时候,docker不需要像虚拟机一样重新加载一个操作系统内核,避免引导。虚拟机是加载Guest OS,分钟级别的,而docker是利用宿主机的操作系统,省略了这个复杂的过程,秒级!

Docker常用命令
docker version	#显示docker版本信息
docker info		#显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help	#帮助命令
镜像命令

docker images 查看所有本地的主机的镜像

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   3 weeks ago   13.3kB


#解释
REPOSITORY	镜像的仓库源
TAG			镜像的标签	
IMAGE ID	镜像的id
CREATED		镜像的创建时间
SIZE		镜像的大小

#可选项
  -a, --all             Show all images (default hides
                        intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs  	只显示镜像的id

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-h2J7vLeK-1637583769176)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211021193001531.png)]

docker search 镜像搜索

docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11565     [OK]       
mariadb                           MariaDB Server is a high performing open sou…   4401      [OK]       


#可选项

--filter=STARS=3000		搜索出来的镜像就是STARS大于3000的



Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0lTdIGE8-1637583769177)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211021194116115.png)]

docker pull 下载镜像

#	下载镜像docker pull 镜像名[:tag]

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker pull mysql
Using default tag: latest	# 如果不写tag,默认就是latest
latest: Pulling from library/mysql
b380bbd43752: Pull complete 	# 分层下载,docker image的核心	联合文件系统
f23cbf2ecc5d: Pull complete 
30cfc6c29c0a: Pull complete 
b38609286cbe: Pull complete 
8211d9e66cd6: Pull complete 
2313f9eeca4a: Pull complete 
7eb487d00da0: Pull complete 
4d7421c8152e: Pull complete 
77f3d8811a28: Pull complete 
cce755338cba: Pull complete 
69b753046b9f: Pull complete 
b2e64b0ab53c: Pull complete 
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87	#签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest	#真实地址


#等价于
docker pull mysql
docker pull docker.io/library/mysql:latest 


#指定版本下载
docker pull mysql:5.7

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
b380bbd43752: Already exists 
f23cbf2ecc5d: Already exists 
30cfc6c29c0a: Already exists 
b38609286cbe: Already exists 
8211d9e66cd6: Already exists 
2313f9eeca4a: Already exists 
7eb487d00da0: Already exists 
a71aacf913e7: Pull complete 
393153c555df: Pull complete 
06628e2290d7: Pull complete 
ff2ab8dac9ac: Pull complete 
Digest: sha256:2db8bfd2656b51ded5d938abcded8d32ec6181a9eae8dfc7ddf87a656ef97e97
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

docker rmi 删除镜像

docker rmi -f  镜像id

docker rni -f $(docker images -aq) 
容器命令

下载一个centos镜像测试学习

 docker pull centos

新建容器并启动

docker run [可选参数] image

# 参数说明
--name="Name"	容器名字 tomcat01 tomcat02,用来区分容器
-d		后台方式运行
-it		使用交互方式运行,进入容器查看内容	
-p		指定容器的端口 -p 8080:8080
	-p ip:主机端口:容器端口
	-p 主机端口:容器端口(常用)
	-p 容器端口
	容器端口
-p		随机指定端口	
#	启动并进入容器 
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker run -it centos /bin/bash
[root@a156ea1b81ed /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr




# 从容器退回主机
[root@a156ea1b81ed /]# exit
exit
[root@iZuf6dcdal1ed3wkay21z4Z ~]# ls
install.sh  mc  nohup.out


列出所有在运行的容器

docker ps
-a #列出当前正在运行的容器+带出历史运行过的容器
-n=#显示最近创建的容器
-q	#只显示容器的编号

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED          STATUS                          PORTS     NAMES
a156ea1b81ed   centos        "/bin/bash"   4 minutes ago    Exited (0) About a minute ago             youthful_dewdney
b3396031d584   hello-world   "/hello"      54 minutes ago   Exited (0) 54 minutes ago                 silly_varahamihira
97d5c66a6ee8   hello-world   "/hello"      7 days ago       Exited (0) 7 days ago                     jolly_curran

退出容器

exit	#容器停止并退出
Ctrl + P + Q	#容器不停止退出

删除容器

docker rm 容器id	#删除指定的容器,不能删除正在运行的容器
docker rm -f $(docker ps -aq)	#删除所有的容器
docker ps -a -q|xargs dockr rm	#删除所有的容器

启动和停止容器的操作

docker start 容器id	#启动容器
docker restart 容器id	#重启容器
docker stop 容器id	#停止当前正在运行的容器
docker kill 容器id	#强制停止当前容器
常用的其他命令

后台启动容器

# 命令 docker run -d 镜像名

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker run -d centos
d56dc5aa3b6930744563a111ce124d3e8ffcbe77194f9f3aa25a6842ef40a4c0
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@iZuf6dcdal1ed3wkay21z4Z ~]# 


# 问题docker ps,发现centos停止了

#docker容器使用后台运行,就必须要有要一个前台进程,docker发现没有应用,就会自动停止

#nginx,容器启动后,发现自己没有提供服务,就会立刻停止,就是没有程序了

查看日志

docker logs -tf -tail [数量] 容器id

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
7ec043717284   centos    "/bin/bash"   11 minutes ago   Up 11 minutes             trusting_hodgkin
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker stop 7ec043717284
7ec043717284
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker run -d centos /bin/sh -c "while true;do echo dzhooo;sleep 1;done"
cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES
cb2b62e86479   centos    "/bin/sh -c 'while t…"   3 seconds ago   Up 2 seconds             relaxed_heyrovsky
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker logs -tf --tail 10 cb2b62e86479
2021-10-21T12:44:22.600676466Z dzhooo
2021-10-21T12:44:23.602582338Z dzhooo
2021-10-21T12:44:24.604476676Z dzhooo
2021-10-21T12:44:25.608460525Z dzhooo
2021-10-21T12:44:26.609853539Z dzhooo
2021-10-21T12:44:27.611848934Z dzhooo
2021-10-21T12:44:28.614530633Z dzhooo
2021-10-21T12:44:29.616296839Z dzhooo
2021-10-21T12:44:30.618129928Z dzhooo
2021-10-21T12:44:31.619970376Z dzhooo


#自己编写一段shell脚本
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker run -d centos /bin/sh -c "while true;do echo dzhooo;sleep 1;done"

#显示日志
-tf		#显示日志
--tail number 	#要显示日志条数
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker logs -tf --tail 10 cb2b62e86479


查看容器中进程信息ps

docker top 容器id
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker top cb2b62e86479
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                423692              423673              0                   20:44               ?                   00:00:00            /bin/sh -c while true;do echo dzhooo;sleep 1;done
root                424131              423692              0                   20:47               ?                   00:00:00            /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1

查看镜像的元数据

#命令 docker inspect 容器id 

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker inspect --help

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type
      
      
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker inspect cb2b62e86479
[
    {
        "Id": "cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4",
        "Created": "2021-10-21T12:44:02.002084589Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "while true;do echo dzhooo;sleep 1;done"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 423692,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-10-21T12:44:02.563801588Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4/hostname",
        "HostsPath": "/var/lib/docker/containers/cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4/hosts",
        "LogPath": "/var/lib/docker/containers/cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4/cb2b62e8647905f90cf094a2d16ddb8ae86c3c6ea605d500209191a0a9b362f4-json.log",
        "Name": "/relaxed_heyrovsky",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/ec7b4f5c3f5df818df69a949cf18263810595652f52dffc5c91e77ea5c2d02bd-init/diff:/var/lib/docker/overlay2/c1ceec2d280bb711cf5b4e331a6f864459a5c330de5f7d84a03349cfd60fba3b/diff",
                "MergedDir": "/var/lib/docker/overlay2/ec7b4f5c3f5df818df69a949cf18263810595652f52dffc5c91e77ea5c2d02bd/merged",
                "UpperDir": "/var/lib/docker/overlay2/ec7b4f5c3f5df818df69a949cf18263810595652f52dffc5c91e77ea5c2d02bd/diff",
                "WorkDir": "/var/lib/docker/overlay2/ec7b4f5c3f5df818df69a949cf18263810595652f52dffc5c91e77ea5c2d02bd/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "cb2b62e86479",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "while true;do echo dzhooo;sleep 1;done"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "0153bfe1f2fce5d63a8c8ea5cbd441be157e3047840bfdeddf535e21e51b4223",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/0153bfe1f2fc",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "e7a1b4c13e803324879d6ddc6e42ee8aaaa9b8430a08f68dcc69630405774646",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "508c0c863bed09d68d89bf07871a7222c31b83dbe62b94cc5424435c84634f85",
                    "EndpointID": "e7a1b4c13e803324879d6ddc6e42ee8aaaa9b8430a08f68dcc69630405774646",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

进入当前正在运行的容器

#我们通常容器都是使用后台方式运行的,需要进入容器,修改一些配置


# 方式一
docker exec -it [容器id] /bin/bash

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED        STATUS        PORTS     NAMES
cb2b62e86479   centos    "/bin/sh -c 'while t…"   22 hours ago   Up 22 hours             relaxed_heyrovsky
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker exec -it cb2b62e86479 /bin/bash
[root@cb2b62e86479 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@cb2b62e86479 /]# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Oct21 ?        00:00:25 /bin/sh -c while true;do ech
root       79187       0  0 10:46 pts/0    00:00:00 /bin/bash
root       79265       1  0 10:47 ?        00:00:00 /usr/bin/coreutils --coreuti
root       79266   79187  0 10:47 pts/0    00:00:00 ps -ef

在这里插入图片描述

# 方式二

docker attach 容器id
#docker exec	# 进入容器后开启一个新的终端,可以在了吗操作(常用)

#docker attach	# 进入容器正在执行的终端,不会启动新的进程
从容器内拷贝文件到主机上
docker cp 容器id:容器内路径 目的主机路径

[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker cp a8d8a7a9ec6a:/home/test.java /home

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ejAFHZfn-1637583769179)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211022192022531.png)]

总结

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QlovKEGz-1637583769180)(C:\Users\DZHooo\AppData\Roaming\Typora\typora-user-images\image-20211022190645922.png)]

命令大全
  attach      Attach local standard input, output, and error streams to a running container
  #当前shell下 attach连接指定运行的镜像
  build       Build an image from a Dockerfile # 通过Dockerfile定制镜像
  commit      Create a new image from a container's changes #提交当前容器为新的镜像
  cp          Copy files/folders between a container and the local filesystem #拷贝文件
  create      Create a new container #创建一个新的容器
  diff        Inspect changes to files or directories on a container's filesystem #查看docker容器的变化
  events      Get real time events from the server # 从服务获取容器实时时间
  exec        Run a command in a running container # 在运行中的容器上运行命令
  export      Export a container's filesystem as a tar archive #导出容器文件系统作为一个tar归档文件[对应import]
  history     Show the history of an image # 展示一个镜像形成历史
  images      List images #列出系统当前的镜像
  import      Import the contents from a tarball to create a filesystem image #从tar包中导入内容创建一个文件系统镜像
  info        Display system-wide information # 显示全系统信息
  inspect     Return low-level information on Docker objects #查看容器详细信息
  kill        Kill one or more running containers # kill指定docker容器
  load        Load an image from a tar archive or STDIN #从一个tar包或标准输入中加载一个镜像[对应save]
  login       Log in to a Docker registry #
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

安装Nginx
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b380bbd43752: Already exists 
fca7e12d1754: Pull complete 
745ab57616cb: Pull complete 
a4723e260b6f: Pull complete 
1c84ebdff681: Pull complete 
858292fd2e56: Pull complete 
Digest: sha256:644a70516a26004c97d0d85c7fe1d0c3a67ea8ab7ddf4aff193d9f301670cf36
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
mysql         5.7       938b57d64674   3 days ago    448MB
mysql         latest    ecac195d15af   3 days ago    516MB
nginx         latest    87a94228f133   10 days ago   133MB
hello-world   latest    feb5d9fea6a5   4 weeks ago   13.3kB
centos        latest    5d0da3dc9764   5 weeks ago   231MB
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker run -d --name nginx01 -p 3344:80 nginx
410643740a5dba641aff297d5904c231a0d54702a6a6f46a5dbf707daabc3407
[root@iZuf6dcdal1ed3wkay21z4Z ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
410643740a5d   nginx     "/docker-entrypoint.…"   4 seconds ago   Up 3 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
[root@iZuf6dcdal1ed3wkay21z4Z ~]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>





# 进入容器
[root@iZuf6dcdal1ed3wkay21z4Z ~]#  docker exec -it nginx01 /bin/bash
root@410643740a5d:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@410643740a5d:/# cd /etc/nginx
root@410643740a5d:/etc/nginx# ls
conf.d		mime.types  nginx.conf	 uwsgi_params
fastcgi_params	modules     scgi_params

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值