【Docker】初识与应用场景认知

什么是Docker?###

Docker是一个容器化平台,它以容器的形式将您的应用程序及其所有依赖项打包在一起,以确保您的应用程序在任何环境中无缝运行。

什么是Docker容器?###

Docker容器包括应用程序及其所有依赖项,作为操作系统的独立进程运行.

什么是Docker镜像?###

Docker镜像是Docker容器的源代码,Docker镜像用于创建容器。

Docker的使用场景有哪些?###


①简化配置
②代码流水线管理
③提高开发效率
④隔离应用
⑤整合服务器
⑥调试能力
⑦多租户环境
⑧快速部署
八个Docker的真实应用场景:

Docker必备技能###

dcoker启动/关闭:######
sudo service docker start或
sudo systemctl enable docker  sudo systemctl start docker

sudo service docker stop或
sudo systemctl stop docker
Docker Hello World######

运行交互式的容器######

启动容器(后台模式)######

#列出所有在运行的容器信息
docker ps
#在容器内使用docker logs命令,查看容器内的标准输出
docker logs CONTAINER ID/NAMES
停止容器######
docker stop CONTAINER ID/NAMES
#在容器内使用docker logs命令,查看容器内的标准输出
docker logs CONTAINER ID/NAMES
列出镜像列表######

查找镜像######

拖取镜像######

创建镜像######

当我们从docker镜像仓库中下载的镜像不能满足我们的需求时,我们可以通过以下两种方式对镜像进行更改。
1.从已经创建的容器中更新镜像,并且提交这个镜像.
2.使用 Dockerfile 指令来创建一个新的镜像.
①更新镜像

②我们使用命令 docker build , 从零开始来创建一个新的镜像。为此,我们需要创建一个 Dockerfile 文件,其中包含一组指令来告诉 Docker 如何构建我们的镜像。

设置镜像标签######
#我们可以使用 docker tag 命令,为镜像添加一个新的标签。
docker tag 860c279d2fec runoob/centos:dev
#docker tag 镜像ID,这里是 860c279d2fec ,用户名称、镜像源名(repository name)和新的标签名(tag)。
#使用 docker images 命令可以看到,ID为860c279d2fec的镜像多一个标签。
网络端口映射######


Docker使用###

Usage:	docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/home/yunduo/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -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 "/home/yunduo/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/yunduo/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/yunduo/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  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

Docker使用过程中遇到的问题:###

1.Docker启动Get Permission Denied https://www.cnblogs.com/informatics/p/8276172.html
原因:大概的意思就是:docker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,需要root权限才能访问。
解决方法1:
使用sudo获取管理员权限,运行docker命令
解决方法2:
docker守护进程启动的时候,会默认赋予名字为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令:

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用

2.Docker pull 出现的 error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/
https://blog.csdn.net/sfdst/article/details/69336273

systemctl stop docker
echo "DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io"" | sudo tee -a /etc/default/docker
service docker restart
原文地址:https://www.cnblogs.com/wucaiyun1/p/11159064.html