Docker02 Docker初识:第一个Docker容器和Docker镜像

目录

[TOC]

一、第一个Docker容器

使用docker run 命令时,如果在本地没有改镜像,那么会直接重Docker Hub(一个官方的镜像库)中拉取镜像。

docker run --rm hello-world

# 运行结果展示
Unable to find image ‘hello-world:latest‘ locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pulling fs layer
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96/data?Expires=1525996669&Signature=M6vcU5NqAiIMXSuJowD1zmLStFXMGck436eqPJk6GdSKrx4v~YIkV1DHQpz5aKOQnPIHowmSe6wLPWCn7E4U2my-BNqhbRVr65ndw-fJYO0eucaeRnEp7jkyhfxNJFWzMiVHmk~U595HGt4vZ4E50Umc76xKLvciYl1HGLwJhtw_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.
See ‘docker run --help‘.
[[email protected] ~]$ docker run --rm hello-world
Unable to find image ‘hello-world:latest‘ locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
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/engine/userguide/

二、第一个Docker镜像

2.1 创建Docker镜像准备工作

# 新建一个文件夹hello
mkdir hello
cd hello
# hello中新建一个文件,命名为Dockerfile,文件内容如下:
FROM alpine # 即将构建的镜像是基于名为Apline的镜像
CMD "echo" "Hello World"

2.2 构建Docker镜像

打包镜像

# 将上面的文件打包
docker build -t hello .
# -t 后面的参数是给这个镜像取得标签,.代表重当前路径搜索Dockerfile文件,并执行里面的代码

运行结果

[[email protected] hello]$ docker build -t hello .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM alpine
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest
 ---> 3fd9065eaf02
Step 2/2 : CMD "echo" "Hello World"
 ---> Running in 4891b2d2a317
Removing intermediate container 4891b2d2a317
 ---> 4b1c2e073c23
Successfully built 4b1c2e073c23
Successfully tagged hello:latest

执行镜像

[[email protected] hello]$ docker run --rm hello
Hello World
[[email protected] hello]$ 

原文地址:https://www.cnblogs.com/gupan/p/9021605.html

时间: 2024-08-27 09:13:27

Docker02 Docker初识:第一个Docker容器和Docker镜像的相关文章

.NETCore 实现容器化Docker与私有镜像仓库管理

原文:.NETCore 实现容器化Docker与私有镜像仓库管理 一.Docker介绍 Docker是用Go语言编写基于Linux操作系统的一些特性开发的,其提供了操作系统级别的抽象,是一种容器管理技术,它隔离了应用程序对基础架构(操作系统等)的依赖.相较于虚拟机而言,Docker共享的是宿主机的硬件资源,使用容器来提供独立的运行环境来运行应用.虚拟机则是基于Supervisor(虚拟机管理程序)使用虚拟化技术来提供隔离的虚拟机,在虚拟机的操作系统上提供运行环境!虽然两者都提供了很好的资源隔离,

Docker实战之创建一个tomcat容器

一.Docker与虚拟机的区别 二.Docker学习步骤 2.1:安装宿主操作系统 在VMVare中安装了Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64) 64位操作系统 建议内核在 3.8 以上,执行uname –r 查看内核如下图所示 2.2:更新系统 Ubuntu在安装的过程中没有指定root用户密码的操作,所以我们需要给root用户一个密码 命令如下 sudo passwd 系统会提示Enter New UNIX OR LINU

通过运行一个tomcat容器来记录下初学docker常用的几个命令---容器篇

1.查看容器列表 显示正在运行的容器: [[email protected] HMK]# docker ps 显示所有容器,包括未运行的: [[email protected] HMK]# docker ps -a CONTAINER ID:容器的ID IMAGE:启动容器使用的镜像 CREATED:创建时间 STATUS: 状态 PORTS:端口映射信息 NAMES:容器名称 2.使用tomcat镜像启动一个容器,并挂载宿主机中的/HMK/helloword/webapps/HelloWorl

如何启动一个已经创建的docker 容器,并进入SHELL 对其操作

有同学在docker下安装了nginx 但是不知道目录在哪,可以使用命令 sudo find / -name "50x.html" 因为nginx里必定会有50x.html ,所以查找它,结果发现nginx的目录在docker容器里,如果操作它,就需要进入容器的shell. 必须先启动容器 sudo docker start "容器ID" 然后使用下边的命令进入shell sudo docker exec -it "容器ID" bash

在 Docker 上运行一个 RESTful 风格的微服务

tags: Microservice Restful Docker Author: Andy Ai Weibo:NinetyH GitHub: https://github.com/aiyanbo/docker-restful-demo 实现构思 1. 使用 Maven 进行项目构建 2. 使用 Jersey 实现一个 RESTful 风格的微服务 3. 在 Docker 里面执行 mvn package 对项目打包 4. 在 Docker 容器里运行这个微服务 实现一个微服务 场景 & 需求

docker学习笔记2:容器操作

一.列出主机上已经创建的容器 docker ps -a 二.创建交互式容器 命令: docker run -i -t ubuntu /bin/bash 其中-i -t 表示创建一个提供交互式shell的容器. ubuntu是镜像名,如果本地不存在,回到仓库中下载. /bin/bash 是指定容器创建后立即执行的命令. 注意:每个容器都有一个唯一的ID,作为容器的标识.每个容器也有个唯一的名称,在用docker run命令创建时可以通过 --name 名称 来指定,如果不指定,系统会自动产生一个名

Docker系列(二)---容器

创建容器 新建容器 方法一: [[email protected]]# docker run -it centos:6 echo "hello" hello 方法二: [[email protected]]# docker create -it centos:6 echo "hello" c97b4ca48ce2f2065230398c57955c9ab9a31a3af9301217a626a16471697451 使用方法二创建的容易处于停止状态,使用docker

通过docker创建并使用apache容器

目标: 制作一个承载apache的镜像,并在一个Linux内启动5个apache容器对外提供服务 1.安装apache docker run -t -i --name=qxy_apache centos yum -y install httpd exit 2.制作镜像 docker commit qxy_apache qxy_apache:v1.0 [[email protected]-1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIR

理解Docker(3):Docker 使用 Linux namespace 隔离容器的运行环境

1. 基础知识:Linux namespace 的概念 Linux 内核从版本 2.4.19 开始陆续引入了 namespace 的概念.其目的是将某个特定的全局系统资源(global system resource)通过抽象方法使得namespace 中的进程看起来拥有它们自己的隔离的全局系统资源实例(The purpose of each namespace is to wrap a particular global system resource in an abstraction th