docker入门2---docker的初体验-LMLPHP

Tomxin7

第一个Docker镜像?

1、查看当前镜像

[root@tomxin docker]# docker images
结果应该是当前系统暂时还没有任何镜像

2、下载“hello-world”镜像

[root@tomxin docker]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for docker.io/hello-world:latest

3、再次查看镜像

[root@tomxin docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 4ab4c602aa5e 5 weeks ago 1.84 kB

第一个docker容器

1、查看容器

[root@tomxin docker] docker ps -a
应该暂时还没有容器

2、运行“hello-world”,运行成功后,docker会创建一个容器,上面输出了hello-world这个项目运行,docker所做的工作步骤

[root@tomxin docker]# docker run hello-world

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/

3、查看全部容器,可以看到在run镜像之后,创建了一个容器

[root@tomxin docker] docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                    NAMES
b44b6c29ac29 hello-world "/hello" 14 minutes ago Exited (0) 14 minutes ago

注意:如果没有提前pull镜像,直接运行docker run命令也是可以的,在本地没有找到对应镜像,docker会自动请求远程仓库并且下载、启动镜像,下图展示了docker基本的工作原理。

docker入门2---docker的初体验-LMLPHP

05-26 01:56