Docker的所有命令

Docker命令帮助文档(重要)

[root@fedora ~]# docker --help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.8.2-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc., v0.17.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a 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
  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
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  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

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

作业练习


三个作业:

作业1告诉我们暴露端口的重要性

作业2告诉我们进入容器的重要性

作业3告诉我们查看当前容器状态的重要性,如何修改容器运行的环境


作业1Docker 安装 Nginx

# 1. 搜索镜像 search 建议去docker hub搜索,可以看到帮助文档
# 2. 拉取镜像 pull
# 3. 运行测试
# -d 后台运行
# --name 给容器命名
# -p 宿主机端口:容器内部端口

[root@fedora ~]# docker search -f stars=200 nginx
NAME      DESCRIPTION                STARS     OFFICIAL   AUTOMATED
nginx     Official build of Nginx.   16975     [OK]   

[root@fedora ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
......
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

[root@fedora ~]# docker run -d -p 1122:80 --name nginx01 nginx
7aa4fb14a2e676a27f24fa54598590d8999a6e3009e89da0bdcbf57b4c796f3e

[root@fedora ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
7aa4fb14a2e6   nginx     "/docker-entrypoint.…"   7 seconds ago   Up 6 seconds   0.0.0.0:1122->80/tcp, :::1122->80/tcp   nginx01
[root@fedora ~]# curl localhost:1122
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
......
</html>

端口暴露示意图

思考问题:我们每次改动nginx配置文件,都需要进入容器内部?十分的麻烦,要是可以在容器外部提
供一个映射路径,达到在容器修改文件名,容器内部就可以自动修改? 数据卷!


作业2:Docker装 Tomcat

# 官方的使用
docker run -it --rm tomcat:9.0
# 之前的启动都是后台,停止了容器,容器还是可以查到
# docker run -it --rm image 一般是用来测试,用完就删除(暂时不建议)
--rm Automatically remove the container when it exits
# 下载
docker pull tomcat
# 启动运行
[root@fedora ~]# docker run -d -p 8080:8080 --name tomcat01 tomcat
82a94d73adf68b2f913cb5effecb985f6ffef635a209d50bcaed842630af8b18
# 测试没有问题
[root@fedora ~]# curl localhost:8080
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/10.0.14</h3></body></html>
# 进入容器
[root@fedora ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                       NAMES
82a94d73adf6   tomcat    "catalina.sh run"   57 seconds ago   Up 56 seconds   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   tomcat01
[root@fedora ~]# docker exec -it tomcat01 /bin/bash
root@82a94d73adf6:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  native-jni-lib  temp  webapps  webapps.dist  work
# 发现问题 
# 1、linux命令少了 2.没有webapps
# 阿里云镜像(阉割版),它为保证最小镜像,将不必要的都剔除了→保证最小可运行环境!

思考问题:我们以后要部署项目,如果每次都要进入容器是不是十分麻烦?要是可以在容器外部提供一
个映射路径,webapps,我们在外部放置项目,就自动同步内部就好了!

[root@fedora ~]# docker exec -it tomcat01 /bin/bash
root@82a94d73adf6:/usr/local/tomcat# ls
BUILDING.txt	 LICENSE  README.md	 RUNNING.txt  conf  logs	    temp     webapps.dist
CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin	      lib   native-jni-lib  webapps  work
root@82a94d73adf6:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@82a94d73adf6:/usr/local/tomcat# cd webapps
root@82a94d73adf6:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager

 

作业3:部署es+kibana

# es 暴露的端口很多!
# es 十分耗内存
# es 的数据一般需要放置到安全目录!挂载
# --net somenetwork ? 网络配置
# 下载启动elasticsearch(Docker一步搞定)
[root@fedora ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
78477d95a6dcb5d4135bbd78719d6b6557fac57dfa68a787f6e1f7bda1a1297c
[root@fedora ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                                                  NAMES
78477d95a6dc   elasticsearch:7.6.2   "/usr/local/bin/dock…"   8 seconds ago   Up 4 seconds   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch
[root@fedora ~]# curl localhost:9200
{
  "name" : "78477d95a6dc",
  "cluster_name" : "docker-cluster",
......
  "tagline" : "You Know, for Search"
}
# 查看docker容器使用内存情况(每秒刷新,也挺耗内存的一个命令)
[root@fedora ~]# docker stats
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O         BLOCK I/O        PIDS
78477d95a6dc   elasticsearch   0.38%     1.296GiB / 3.825GiB   33.88%    7.95kB / 984B   110MB / 14.7MB   43

# 关闭,添加内存的限制,修改配置文件 -e 环境配置修改
[root@fedora ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2

[root@fedora ~]# docker stats
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT   MEM %     NET I/O       BLOCK I/O        PIDS
6495483231dc   elasticsearch   0.58%     425MiB / 3.825GiB   10.85%    3.58kB / 0B   109MB / 14.7MB   42

作业:使用kibana连接es?思考网络如何才能连接

 

Docker 可视化

Portainer(先用这个)

Rancher(CI/CD)

# 运行如下命令即可 打开可视化服务
docker run -d -p 8080:9000 
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
[root@fedora ~]# docker run -d -p 8080:9000 
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
94cfa856b2b1: Pull complete 
49d59ee0881a: Pull complete 
a2300fd28637: Pull complete 
Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f
Status: Downloaded newer image for portainer/portainer:latest
2101d5d67c5ab929fa8b3ad21040fc09fd29dc8cc1a4292f2c4a01c4c8018772

在浏览器中输入 ip:8080,即可本地访问

设置admin密码

选择本地连接

进入GUI控制面板

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/simplerude/p/16397475.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!