docke 基本安装使用

 

 

 

特性

容器

虚拟机

启动

秒级

分钟级

硬盘使用

一般为 MB

一般为 GB

性能

接近原生

系统支持量

单机支持上千个容器

一般几十个

容器三大基本概念
镜像 image
容器 container
仓库 repository
docker整个生命周期就是这三个概念。

安装docker
1.卸载旧版本
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

2.设置存储库
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
sudo yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.安装docker社区版
sudo yum install docker-ce
4.启动关闭docker
systemctl start docker

docker 镜像加速

#一条命令加速
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://95822026.m.daocloud.io

docker基础命令注释

[root@docker ~]# docker --help

Usage:
docker [OPTIONS] COMMAND [arg...]

       docker daemon [ --help | ... ]

       docker [ --help | -v | --version ]

A
self-sufficient runtime for containers.

 

Options:

  --config=~/.docker              Location of client config files  #客户端配置文件的位置

  -D, --debug=false               Enable debug mode  #启用Debug调试模式

  -H, --host=[]                   Daemon socket(s) to connect to  #守护进程的套接字(Socket)连接

  -h, --help=false                Print usage  #打印使用

  -l, --log-level=info            Set the logging level  #设置日志级别

  --tls=false                     Use TLS; implied by--tlsverify  #

  --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA  #信任证书签名CA

  --tlscert=~/.docker/cert.pem    Path to TLS certificate file  #TLS证书文件路径

  --tlskey=~/.docker/key.pem      Path to TLS key file  #TLS密钥文件路径

  --tlsverify=false               Use TLS and verify the remote  #使用TLS验证远程

  -v, --version=false             Print version information and quit  #打印版本信息并退出


Commands:

    attach    Attach to a running container  #当前shell下attach连接指定运行镜像

    build     Build an image from a Dockerfile  #通过Dockerfile定制镜像

    commit    Create a new image from a container's changes  #提交当前容器为新的镜像

    cp    Copy files/folders from a container to a HOSTDIR or to STDOUT  #从容器中拷贝指定文件或者目录到宿主机中

    create    Create a new container  #创建一个新的容器,同run 但不启动容器

    diff    Inspect changes on a container's filesystem  #查看docker容器变化

    events    Get real time events from the server#从docker服务获取容器实时事件

    exec    Run a command in a running container#在已存在的容器上运行命令

    export    Export a container's filesystem as a tar archive  #导出容器的内容流作为一个tar归档文件(对应import)

    history    Show the history of an image  #展示一个镜像形成历史

    images    List images  #列出系统当前镜像

    import    Import the contents from a tarball to create a filesystem image  #从tar包中的内容创建一个新的文件系统映像(对应export)

    info    Display system-wide information  #显示系统相关信息

    inspect    Return low-level information on a container or image  #查看容器详细信息

    kill    Kill a running container  #kill指定docker容器

    load    Load an image from a tar archive or STDIN  #从一个tar包中加载一个镜像(对应save)

    login    Register or log in to a Docker registry#注册或者登陆一个docker源服务器

    logout    Log out from a Docker registry  #从当前Docker registry退出

    logs    Fetch the logs of a container  #输出当前容器日志信息

    pause    Pause all processes within a container#暂停容器

    port    List port mappings or a specific mapping for the CONTAINER  #查看映射端口对应的容器内部源端口

    ps    List containers  #列出容器列表

    pull    Pull an image or a repository from a registry  #从docker镜像源服务器拉取指定镜像或者库镜像

    push    Push an image or a repository to a registry  #推送指定镜像或者库镜像至docker源服务器

    rename    Rename a container  #重命名容器

    restart    Restart a running container  #重启运行的容器

    rm    Remove one or more containers  #移除一个或者多个容器

    rmi    Remove one or more images  #移除一个或多个镜像(无容器使用该镜像才可以删除,否则需要删除相关容器才可以继续或者-f强制删除)

    run    Run a command in a new container  #创建一个新的容器并运行一个命令

    save    Save an image(s) to a tar archive#保存一个镜像为一个tar包(对应load)

    search    Search the Docker Hub for images  #在docker
hub中搜索镜像

    start    Start one or more stopped containers#启动容器

    stats    Display a live stream of container(s) resource usage statistics  #统计容器使用资源

    stop    Stop a running container  #停止容器

    tag         Tag an image into a repository  #给源中镜像打标签

    top       Display the running processes of a container #查看容器中运行的进程信息

    unpause    Unpause all processes within a container  #取消暂停容器

    version    Show the Docker version information#查看容器版本号

    wait         Block until a container stops, then print its exit code  #截取容器停止时的退出状态值

 

Run 'docker COMMAND --help' for more information on a command.  #运行docker命令在帮助可以获取更多信息

dockefile的学习

指令如下
#你的项目依赖于什么操作系统,这里就指定什么操作系统 
FROM scratch #制作base image 基础镜像,尽量使用官方的image作为base image
FROM centos #使用base image
FROM ubuntu:14.04 #带有tag的base image

#label标签 ,告诉别人,这个dockerfile是谁写的
LABEL version=“1.0” #容器元信息,帮助信息,Metadata,类似于代码注释
LABEL     maintainer=“yc_uuu@163.com"


#run指令是一个万能指令 

#对于复杂的RUN命令,避免无用的分层,多条命令用反斜线换行,合成一条命令!
RUN yum update && yum install -y vim \
    Python-dev #反斜线换行
RUN /bin/bash -c "source $HOME/.bashrc;echo $HOME”

#
WORKDIR /root #相当于linux的cd命令,改变目录,尽量使用绝对路径!!!不要用RUN cd
WORKDIR /test #如果没有就自动创建
WORKDIR demo #再进入demo文件夹
RUN pwd     #打印结果应该是/test/demo


# ADD是可以将本地代码,添加到容器空间内
# ADD不仅仅是添加,还可以解压缩文件,注意!!

ADD and COPY 
ADD hello /  #把本地文件添加到镜像中,吧本地的hello可执行文件拷贝到镜像的/目录
ADD test.tar.gz /  #添加到根目录并解压




WORKDIR /root
ADD hello test/  #进入/root/ 添加hello可执行命令到test目录下,也就是/root/test/hello 一个绝对路径


#copy 就是将宿主机的文件,拷贝到容器空间内,且没有解压效果 


COPY hello test/  #等同于上述ADD效果

ADD与COPY
   - 优先使用COPY命令
    -ADD除了COPY功能还有解压功能
    
    
    
添加远程文件/目录使用curl或wget

ENV #环境变量,尽可能使用ENV增加可维护

ENV MYSQL_VERSION 5.7 #设置一个mysql常量

RUN yum install -y mysql-server=“${MYSQL_VERSION}”


#dockerfile实战,构建自己的flaks镜像 

1.准备一个flask代码文件,内容如下
cat s18-flask.py 
#coding:utf8
from flask import Flask
app=Flask(__name__)
@app.route('/')
def hello():
    return "hello,i am docker"
if __name__=="__main__":
    app.run(host='0.0.0.0',port=8080)

    
2.编写dockerfile
FROM centos        #指定centos基础镜像 
COPY CentOS-Base.repo /etc/yum.repos.d/        #拷贝宿主机的文件,到容器空间下
COPY epel.repo /etc/yum.repos.d/             #拷贝宿主机的文件,到容器空间下
RUN yum clean all                             #执行清空yum缓存的命令
RUN yum install python-setuptools -y        #想安装python依赖工具
RUN easy_install flask                        #是想让docker自动的帮咱们安装python2的flask模块
COPY s18-flask.py /opt/                        #把本地的代码文件,拷贝到容器的/opt目录下 
WORKDIR /opt                                #进入到/opt目录下
EXPOSE 8080                                    #暴露容器的8080端口,供给外部宿主机去访问
CMD ["python","s18-flask.py"]                #cmd代表你要执行的命令



3.构建build这个dockerfile
确保文件都准备好了,如下所示
[root@wangdachui s18dockerfile]# ls
CentOS-Base.repo  Dockerfile  epel.repo  s18-flask.py


4.构建dockerfile
docker build .  

5.通过自己构建的镜像,运行一个flask程序
docker run -d -it --name flask  -p 5555:8080  s18-flask 

6.通过浏览器去访问linux宿主机的 5555端口,即可访问到flask程序

docker 仓库 构建 私有镜像

1.下载docker私有镜像
docker pull registry

2.修改docker的配置文件
#修改如下配置文件
vim /etc/docker/daemon.json


修改内容如下
{"registry-mirrors": ["http://95822026.m.daocloud.io"],
"insecure-registries":["192.168.226.128:5000"]
}

3.修改docker的service配置文件,让它加载/etc/docker/daemon.json
修改如下文件
vim /lib/systemd/system/docker.service

添加如下配置到 [service]代码块中
EnvironmentFile=-/etc/docker/daemon.json

4.重启docker的服务
systemctl daemon-reload
systemctl restart docker

5.重新启动一个私有镜像仓库的容器实例

docker run --privileged=true -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry

--privileged=true docker容器的安全机制:设置特权级运行的容器


6.推送本地镜像,到私有仓库中
docker push 192.168.226.128:5000/s18-hello-world

7.检查docker私有仓库的api地址,检查json数据
http://192.168.226.128:5000/v2/_catalog

8.尝试下载私有仓库的镜像
docker pull 192.168.226.128:5000/s18-hello-world

 

rabbitmq 消息队列的学习

注意,保证服务器的内存足够,磁盘足够,以及删除/etc/hosts中没有用的dns解析 

1.优点,能够保证消息数据持久化,不丢失


安装学习rabbitmq消息队列,配置好阿里云的yum源

1.yum -y install erlang  rabbitmq-server

2.启动rabbitmq服务端
systemctl start rabbitmq-server

3.开启rabbitmq的web控制台
rabbitmq-plugins enable rabbitmq_management

4.重启后生效web界面
http://192.168.226.128:15672/

5.创建rabbitmq用户
sudo rabbitmqctl add_user yangyang 1236.设置用户的权限,为admin管理员权限
sudo rabbitmqctl set_user_tags yangyang administrator

7.允许yangyang这个用户对所有的队列进行读写
sudo rabbitmqctl set_permissions -p "/" yangyang ".*" ".*" ".*"


8.可以用yangyang登录 rabbitmq的后台界面管理了

rabbitmq练习ack机制,消息队列持久化,查看博客
https://www.cnblogs.com/pyyu/p/10318053.html

 

转载于:https://www.cnblogs.com/zaizai1573/p/10674170.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值