docker

Docker体验(一)

2020-09-18  本文已影响0人  十毛tenmao

最近项目的整体服务要迁移到新的容器云平台,所以趁机再加强对docker和kubernetes的了解。

概念

docker流程.png

容器是一个比较独立的领域,其中有很多概念需要理顺。

上手体验

# 查看版本号
docker -v
docker version

# docker服务整体信息
docker info
# 执行hello-world,如果本地不存在则从仓库下载
C:\WINDOWS\system32>docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete                                                                                                                                                           Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
docker run --detach --publish=80:80 --name=webserver nginx

常用管理命令

容器管理

docker ps/ docker container ps
$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker container start [containerID/conainerName]

镜像管理

C:\WINDOWS\system32>docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              7e4d58f0e5f3        7 days ago          133MB
hello-world         latest              bf756fb1ae65        8 months ago        13.3kB

对于那些不会自动终止的容器,必须使用docker container kill 命令手动终止。
$ docker container kill [containID]

$ docker image pull library/hello-world

查看环境变量

➜  ~ docker run -it alpine env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=2d10fb9a588c
TERM=xterm
HOME=/root

参考

上一篇 下一篇

猜你喜欢

热点阅读