docker

https://www.docker.com/

https://docs.docker.com/

Docker 为什么会出现?

应用程序部署从开发环境迁移到测试、生产环境出现的问题。

开发人员利用 Docker 可以消除协作编码时“在我的机器上可正常工作”的问题。

docker镜像,一次构建,到处运行。Build,ship and run any app,anywhere

  • 更高效的利用系统资源
  • 更快速的启动时间
  • 一致的运行环境
  • 持续交付和部署
  • 更轻松的迁移
  • 更轻松的维护和扩展

Docker 是什么,能干什么?与虚拟机有什么区别?

docker 是一个开源的应用容器引擎。

容器化技术:容器化技术不是一个模拟完整操作系统的技术

容器在Linux上本地运行,并与其他容器共享主机的内核。 它运行一个离散进程,不占用任何其他可执行文件更多的内存,从而使其轻巧。

相比之下,虚拟机(VM)运行具有“虚拟机管理程序”对主机资源的虚拟访问权的成熟“guest”操作系统。 通常,VM会产生大量开销,超出了应用程序逻辑所消耗的开销。

docker 是怎么工作的?

Docker是一个Client-Server结构的系统,docker的server以守护进程的方式运行在Linux上,通过socket从客户端访问。

安装docker

Install engine on centos https://docs.docker.com/engine/install/centos/

remove old

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

安装yum repository

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装DOCKER ENGINE

$ sudo yum install docker-ce docker-ce-cli containerd.io

启动Docker.

$ sudo systemctl start docker

验证 Docker Engine 是否安装成功 by running the hello-world image.

$ sudo docker run hello-world

docker常用命令 docker –help

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:
  builder     Manage builds
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  engine      Manage the docker engine
  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
  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

docker后台启动

  • docker run -d <image_name>
  • docker run -i -t <image_name> 然后Ctrl+P+Q即可退出控制台,但是容器没有退出,可使用命令查看:
    docker ps
-d, --detach Run container in background and print container ID
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY

portrainer可视化

docker镜像的分层原理

docker制作镜像

Docker根据Container生成Image : docker commit [container name] [new image name]

容器数据卷

DockerFile

Docker网络

Docker Compose