docker

作者: 初庆钊 | 来源:发表于2017-12-29 21:00 被阅读0次

    术语

    镜像:系统配置清单,用来创造容器,相当于菜谱
    容器:是镜像的实现,相当于照着菜谱做菜。

    docker 镜像源

    1. 改json 新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者%programdata%\docker\config\daemon.json(Windows) 来配置 Daemon。
      请在该配置文件中加入(没有该文件的话,请先建一个):
    ustc   "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
    163     http://hub-mirror.c.163.com
    中国官方    https://registry.docker-cn.com
    
    1. -registry-mirror参数
    docker run hello-world --registry-mirror=https://docker.mirrors.ustc.edu.cn
    
    1. 修改/etc/default/docker
    mirror=https://docker.mirrors.ustc.edu.cn"
    

    Docker registry 拉取镜像

    alpine 是镜像名称,是一个轻量级的linux 发行版

    docker image pull alpine
    

    下面一条命令显示本地的镜像

    docker image ls
    

    运行container

    docker container run 镜像名 运行的命令
    

    -it 可以保持container 不退出,进行交互。

     docker container run -it alpine /bin/sh
    

    列出正在运行的container,如果加上-a则是全部的(包括已经停止的)container

    docker container ls
    
    docker container ls -a
    

    新建自定义docker镜像

    docker build -t tutorial -f ./dockerfile.txt  ./
    

    从镜像创建和运行容器

    docker run -it --name container1 --net=host -v E:/docker/:/ds tutorial
    

    简单镜像文件

    # reference: https://hub.docker.com/_/ubuntu/
    FROM ubuntu:16.04
    
    # Adds metadata to the image as a key value pair example LABEL version="1.0"
    LABEL maintainer="Hamel Husain <www.github.com/hamelsmu>"
    
    ##Set environment variables
    ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
    
    RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
        build-essential \
        byobu \
        curl \
        git-core \
        htop \
        pkg-config \
        python3-dev \
        python3-pip \
        python-setuptools \
        python-virtualenv \
        unzip \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
    
    RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
        wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.0.1-Linux-x86_64.sh -O ~/anaconda.sh && \
        /bin/bash ~/anaconda.sh -b -p /opt/conda && \
        rm ~/anaconda.sh
    
    ENV PATH /opt/conda/bin:$PATH
    
    RUN pip3 --no-cache-dir install --upgrade \
            altair \
            sklearn-pandas
    
    # Open Ports for Jupyter
    EXPOSE 7745
    
    #Setup File System
    RUN mkdir ds
    ENV HOME=/ds
    ENV SHELL=/bin/bash
    VOLUME /ds
    WORKDIR /ds
    ADD run_jupyter.sh /ds/run_jupyter.sh
    RUN chmod +x /ds/run_jupyter.sh
    
    # Run the shell
    CMD  ["./run_jupyter.sh"]
    
    

    相关文章

      网友评论

          本文标题:docker

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