什么是Docker

安装Docker
Docker安装教程.
这里有多个linux发行版的安装教程很简单,照着做就完事了。
创建属于自己的Docker镜像
创建所需文件
[root@ecs-25e3 ~]# mkdir NginxDocker
[root@ecs-25e3 ~]# cd NginxDocker/
[root@ecs-25e3 NginxDocker]# touch Dockerfile
1.创建一个镜像文件夹
2.进入文件夹
3.创建一个Dockerfile文件(这个是创建镜像关键文件 名字就要是Dockerfile)
编写Dockerfile
[root@ecs-25e3 NginxDocker]# vim Dockerfile
FROM nginx
MAINTAINER Method.Jiao
RUN echo '<h1>Hello, MyDocker!</h1>' > /usr/share/nginx/html/index.html
输入上述内容之后 wq保存退出vim
编写Dockerfile制作自己的镜像
[root@ecs-25e3 NginxDocker]# docker build -t methodjiao/nginx_hello:v1 .
-t 是为新镜像设置仓库和名称,其中 methodjiao 为仓库名, nginx_hello 为镜像名, :v1为标签(不添加为默认 latest )v1后边有个 .
然后就会输出下边这些信息
Sending build context to Docker daemon 2.048 kB
Step 1/3 : FROM nginx
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
b8f262c62ec6: Pull complete
a6639d774c21: Pull complete
22a7aa8442bf: Pull complete
Digest: sha256:9688d0dae8812dd2437947b756393eb0779487e361aa2ffbc3a529dca61f102c
Status: Downloaded newer image for docker.io/nginx:latest
---> ab56bba91343
Step 2/3 : MAINTAINER Method.Jiao
---> Running in d75dbd121379
---> b81452c37f3e
Removing intermediate container d75dbd121379
Step 3/3 : RUN echo '<h1>Hello, MyDocker!</h1>' > /usr/share/nginx/html/index.html
---> Running in 94d4240cb7af
---> 2aae682118d7
Removing intermediate container 94d4240cb7af
Successfully built 2aae682118d7
到这里 我们输入一下 docker images命令,可以看到我们镜像已经创建完毕了。

输入 docker run -d -P methodjiao/nginx_hello:v1运行一下

输入ip+端口进浏览器访问一下,如下图就完成了。

Docker打包上传
如果有同学镜像名之前起的和自己的dockerid不一样,这里需要将镜像改名,在名称前加上自己的docker hub的Docker ID,即我是methodjiao
[root@ecs-25e3 ~]# docker tag 736dd6179611 methodjiao/nginx_hello:v1
如果名字一致的话忽略上述步骤,执行下图的。
[root@ecs-25e3 NginxDocker]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (methodjiao): methodjiao
Password:
Login Succeeded
[root@ecs-25e3 NginxDocker]# docker push methodjiao/nginx_hello:v1
看到下图的东西就证明ok了

再去自己docker账户内看一看

拉取上传的镜像
笔者换了macbook来测试 键入如下(同学们也可以直接输入下面的命令来获取我上传的镜像):
docker pull methodjiao/nginx_hello:v1

输入 docker run -d -P 2aae682118d7运行,然后打开浏览器输入地址

还是一样的味道!
1182

被折叠的 条评论
为什么被折叠?



