美文网首页
2019-02-26Docker学习

2019-02-26Docker学习

作者: Purson | 来源:发表于2019-02-26 17:23 被阅读0次

最近在找工作,在万年俱灰之际,Sheldon老师找到我,说有个测试岗位适合,我特别珍惜这次机会,老师给了一些资料让我学习,周三就去他们办公室见个面。
学习资料如下:

安装一个 Docker 的环境

[https://github.com/dwyl/learn-docker](https://github.com/dwyl/learn-docker)

运维相关

[https://logz.io/learn/docker-monitoring-elk-stack/](https://logz.io/learn/docker-monitoring-elk-stack/)

DockerFile的最佳实践

[https://docs.docker.com/develop/develop-images/dockerfile_best-practices/](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)

Kubernetes 是 Google 开源的容器集群管理系

阅读下官方教程

[https://kubernetes.io/docs/home/](https://kubernetes.io/docs/home/)

BootCamp教程

[https://kubernetesbootcamp.github.io/kubernetes-bootcamp/](https://kubernetesbootcamp.github.io/kubernetes-bootcamp/)

我对docker的理解,它是一个开源的类虚拟机的东西,有着比虚拟机优秀的性能,能快速封装软件环境,提供微服务。docker有三层,从低到高分别是container、service 、stack. 底层的container相当于image的实例,service相当于某一个功能,比如数据库、app、前端等;stack通过YAML格式的compose文件将服务组装起来。其中的docker-machine能轻易地实现分布式应用以及部署。

以下是官方常用命令:

# docker build -t hello . Create image using this directory's Dockerfile
# docker run -p 4000:80 hello Run friendlyname mapping port 4000 to 80
# docker run -d  -p 4000:80 hello Same thing, but in detached mode
# docker container ls List all running containers
# docker container ls -a List all containers, even those not running
# docker container stop <hash> Gracefully stop the specified container
# docker container kill <hash> Force shutdown of the specified container
# docker container rm <hash> Remove specified container from this machine 
# docker container rm $(docker image ls -a -q) Remove all containers
# docker image ls -a List all images on this machine
# docker image rm <image id> remove sepcified image from this machine
# docker image rm $(docker image ls -a -q) Remove all images from this machine
# docker login Login in this CLI session using your Docker credentials
# docker tag <image> username/repositoty:tag # Tag <image> for upload to registry
# docker push username/repository:tag  #Upload taged image to registry
# docker run username/repository:tag # Run image from a registry

# docker stack ls # List stacks or apps
# docker stack deploy -c <composefile> <appname># Run the sepcified Compose file
# docker service ls # List running services associated with an app
# docker service ps <service> # List tasks associated with an app
# docker inspect <task or container> # Inspect task or container
# docker container ls  -q # List container IDs
# docker stack rm <appname> # Tear down an application
# docker swarm leave --force # Take down a sigle node swarm from the manager

# docker-machine ssh myvm1 "docker swarm init --advertise-addr <myvm1 ip>"
# docker-machine create myvm2 -d virtualbox --virtualbox-boot2docker-url=/Users/purson/.docker/machine/cache/boot2docker.iso #create a vm
# docker-machine env myvm1 # View basic information about your node
# docker-machine ssh myvm1 "docker ls node" #List the nodes in your swarm
# docker-machine ssh myvm1 "docker inspect <node ID>"  #Inspect a node
# docker-machine ssh myvm1 "docker swarm join-token -q worker" # View join token
# docker-machine ssh myvm1 # Open a SSH session with the VM; type 'exit' to end
# docker node list # View nodes in Swarm(while log on to manager) 
# docker-machine ssh myvm2 "docker swarm leave" # Make the worker leave the swarm
# docker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarm
# docker-machine ls # List VMs , astrisk shows which VM this shell is talking to
# docker-machine start myvm1 # Start a VM that is currently not running 
# docker-machine env myvm1 # Show envirement variables and command for myvm1.
# eval $(docker-machine env myvm1) # Mac command to connect shell to myvm1
# docker stack deploy -c <file> <app> # Deploy an app; command shell must be set to talk to manager(myvm1), uses local compose file
# docker-machine scp docker-compose.yml myvm1:~ # Copy file to node's home dir (only required if you use ssh  connect to manager and deploy the app )
# docker-machine ssh myvm1 "docker stack deploy -c <file> <app>" # Deploy an app using ssh(you must have first copied the Compose file to myvm1)
# eval $(docker-machine env -u) #Disconnect shell from vms, use native docker
# docker-machine stop $(docker-machine ls -q)# Stop all running VMs
# docker-machine rm $(docker-machine ls -q) # Delete all VMs and their disk images

有几个阅读官方文档踩过的坑:
官方文档地址:https://docs.docker.com/get-started/
1.app.py文件最后一句 if name == "main": 没有indent, 导致服务无法开启。
2.虚拟机启动,由于我用手机热点,加上github慢,所以不能用docker-machine create --driver virtualbox myvm1,先将boot2docker.iso下载到本地,
改为:docker-machine create myvm2 -d virtualbox --virtualbox-boot2docker-url=/Users/purson/.docker/machine/cache/boot2docker.iso
3.在第四节 swarm,使用docker stack deploy -c 无法访问分布式节点,目前还未有解,先把整个流程看完再算。

阅读运维相关的https://logz.io/learn/docker-monitoring-elk-stack/ 踩到的坑:
1.在构建java环境的时候,由于ubuntu 16.10不再被支持,所以无法下载相关包,最后Dockerfile更改了ubuntu版本为16.04,源更换为清华的:

FROM ubuntu:16.04
MAINTAINER Author name

RUN rm /etc/apt/sources.list
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe \
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse \
" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y python-software-properties software-properties-common
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer

RUN useradd -d /home/esuser -m esuser
WORKDIR /home/esuser
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

相关文章

  • 2019-02-26Docker学习

    最近在找工作,在万年俱灰之际,Sheldon老师找到我,说有个测试岗位适合,我特别珍惜这次机会,老师给了一些资料让...

  • 学习学习学习

    第三天了,连续三天,早上睁眼开始,看视频,做课件,连续作业,直到晚上十二点才睡觉。吃饭不规律,想起来就吃,感觉不饿...

  • 学习学习学习

    23岁的我,才真正明白,什么是学习,什么是努力,努力和不努力真的不同,就好比同样是一篇稿子,我用一周背下来,有的人...

  • 学习学习学习!

    妈妈总是让我学习,我只能用装当办法。 方法一: 方法二: 方法三: 方法四: ...

  • 学习学习学习

    001.今天看财富自由之路看了第二遍,而且看了一半,算是完成任务很开心。中间有想放弃的念头,坚持看完。眼睛痛,一直...

  • 学习学习学习

    马自达为什么坚持高压缩比自吸

  • 学习!学习!学习!

    学习的痛苦是暂时的 没有学到的痛苦是永恒的 因为学习而特别充实的一天 很踏实 ~~~~ 2015.11.28.阴天...

  • 学习!学习!学习!

    无数次想要去逃离,可这封闭的世界根本出不去。你没有什么可以抛弃、只能咬着牙带着面具微笑的活下去。 没有那个人、他也...

  • 学习学习学习!

    昨天和今天两个上午,都在学习新媒体运营,学习的过程中心里只有一个想法:这也太套路,太功利了吧。可真应了那句话...

  • 学习,学习,学习!

    近期学习重点有两个方面,一方面是把上一个阶段定下任务的几本书读完,并在读的过程中有输出和转化,让阅读和学习真正能有...

网友评论

      本文标题:2019-02-26Docker学习

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