美文网首页
docker笔记(二)

docker笔记(二)

作者: maxZhang | 来源:发表于2018-06-26 14:35 被阅读6次
连接docker servier,启动docker client,查看docker images:

启动一个nginx服务

docker run -p 8080:80 -d nginx
启动完毕后,打开本地8080端口网页,如下 nginx本地启动8080端口页面

我们改变上面nginx首页内容

cd Desktop
cat > index.html
<html>
<body>hello_docker_nginx</body>
</html>

Ctrl+C退出后,再次把desktop上的index.html拷贝到刚才运行nginx里面

docker cp index.html c741cb63d049://usr/share/nginx/html
完毕之后,我们刷新本地的页面nginx页面,发现页面已经改成了

但是当nginx停止后,这个报错操作不会被保存下来,如果需要保存下来,可以进行commit操作

docker commit -m 'fun' c741cb63d049 nginx-fun

这样我们就提交了新的镜像,查看

docker images

发现多了一份镜像nginx-fun

REPOSITORY          TAG                 IMAGE ID            CREATED                  SIZE
nginx-fun           latest              072f158e3a78        Less than a second ago   109MB
elasticsearch       latest              9b44bde11dd8        7 days ago               486MB
ubuntu              latest              113a43faa138        2 weeks ago              81.2MB
nginx               latest              cd5239a0906a        2 weeks ago              109MB
centos              latest              49f7960eb7e4        3 weeks ago              200MB
hello-world         latest              e38bc07ac18e        2 months ago             1.85kB
alpine              latest              3fd9065eaf02        5 months ago             4.15MB

停止之前的容器

docker stop c741cb63d049

在其启动刚才创建的镜像

docker run -d -p 8080:80 nginx-fun 

此时查看,会发现首页显示还是docker_nginx_hello,这样也就是新建了一个镜像nginx-fun
清除之前已经运行的容器,首先查看所有的容器

docker ps -a

然后运行

docker rm 容器ID

用dockerfile构建自己的镜像
新建文件夹

mkdir /Desktop/d1

新建文件,文件名一般写成Dockerfile

touch Dockerfile

接着往文件内写入数据

FROM alpine:latest
MAINTAINER max
CMD echo "Hello docker"

最后build

//.表示当前文件下所有文件
docker build -t hello_docker .

此时查看刚才的镜像
docker images hello_docker

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello_docker        latest              69b24d25462c        3 seconds ago       4.15MB

相关文章

网友评论

      本文标题:docker笔记(二)

      本文链接:https://www.haomeiwen.com/subject/nbzpyftx.html