docker基础用法

Posted 大头叔叔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker基础用法相关的知识,希望对你有一定的参考价值。


  1. ​​什么是docker​​
  2. OCI&OCF
  1. ​​OCI​​
  2. ​​OCF​​
  1. ​​docker架构​​
  2. ​​docker镜像与镜像仓库​​
  3. ​​docker对象​​
  4. ​​安装及使用docker​​
  5. ​​docker安装​​
  6. ​​docker加速​​
  7. ​​docker常用操作​​
  8. ​​docker event state​​

什么是docker

docker中的容器:

  1. lxc --> libcontainer --> runC

docker基础用法​_常用操作

OCI&OCF

OCI

Open Container-initiative

  1. 由Linux基金会主导于2015年6月创立
  2. 旨在围绕容器格式和运行时制定一个开放的工业化标准
  3. contains two specifications
  1. the Runtime Specification(runtime-spec)
  2. the Image Specification(image-spec)

OCF

Open Container Format

runC is a CLI tool for spawning and running containers according to the OCI specification

  1. Containers are started as a child process of runC and can be embedded into various other systems without having to run a daemon
  2. runC is built on libcontainer, the same container technology powering millions of Docker Engine installations

docker提供了一个专门容纳容器镜像的站点:https://hub.docker.com

docker架构

docker镜像与镜像仓库

为什么镜像仓库名字是Registry而不是repository?在docker中仓库的名字是以应用的名称取名的。

docker基础用法​_sed_02

镜像是静态的,而容器是动态的,容器有其生命周期,镜像与容器的关系类似于程序与进程的关系。镜像类似于文件系统中的程序文件,而容器则类似于将一个程序运行起来的状态,也即进程。所以容器是可以删除的,容器被删除后其镜像是不会被删除的。

docker对象

When you use docker, you are creating and using images, containers, networks, volumes, pluginns, and other objects.

  1. IMAGES
  1. An image is a read-only template with instructions for creating a docker container.
  2. Often, an image is based on another image, with some additional customization.
  3. You might create your own images or you might only use those created by others and published in a registry.
  1. CONTAINERS
  1. A conntainer is a runnable instance of an image.
  2. You can create, run, stop, move, or delete a container using the docker API or CLI.
  3. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

安装及使用docker

docker安装

cd /etc/yum.repos.d/

curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

sed -i s@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g docker-ce.repo

yum -y install docker-ce

docker加速

docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。

docker的加速有多种方式:

  1. docker cn
  2. 中国科技大学加速器
  3. 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)

systemctl start docker

cat > /etc/docker/daemon.json <<EOF

"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]

EOF

systemctl restart docker

docker version

docker info

docker常用操作

命令

功能

docker search

Search the Docker Hub for images

docker pull

Pull an image or a repository from a registry

docker images

List images

docker create

Create a new conntainer

docker start

Start one or more stopped containers

docker run

Run a command in a new container

docker attach

Attach to a runninng container

docker ps

List containers

docker logs

Fetch the logs of a container

docker restart

Restart a container

docker stop

Stop one or more running containers

docker kill

Kill one or more running containers

docker rm

Remove onne or more containers

docker exec

Run a command in a running container

docker info

Display system-wide information

docker inspect

Return low-level information on Docker objects

docker event state

docker基础用法​_sed_03关注公号“金信润天人才培养中心”

以上是关于docker基础用法的主要内容,如果未能解决你的问题,请参考以下文章

docker基础用法

docker基础用法

docker基础用法

docker基础用法

理解Docker:Docker 安装和基础用法

2-Docker基础用法