• WIn10 电脑运行Docker


    参考地址: https://www.cnblogs.com/linjj/p/5606687.html

     https://docs.docker.com/engine/reference/commandline/docker/

    // 这个命令将在你的容器中运行whalesay镜像
    docker run docker/whalesay cowsay boo
    
    // 本地系统中有哪些景象
    docker images
    
    // 运行自己的东西
    docker run docker/whalesay cowsay xyz

    //当前目录下的Dockerfile来创建一个叫做docker-whale的镜像
    docker build -t docker-whale .
    Dockerfile 内容
    
    # Use an official Python runtime as a parent image
    FROM python:2.7-slim
    
    # Set the working directory to /app
    WORKDIR /app
    
    # Copy the current directory contents into the container at /app
    COPY . /app
    
    # Install any needed packages specified in requirements.txt
    RUN pip install --trusted-host pypi.python.org -r requirements.txt
    
    # Make port 80 available to the world outside this container
    EXPOSE 80
    
    # Define environment variable
    ENV NAME World
    
    # Run app.py when the container launches
    CMD ["python", "app.py"]
    
    requirement.txt 内容
    
    Flask
    Redis
    
    app.py内容
    from flask import Flask
    from redis import Redis, RedisError
    import os
    import socket
    
    # Connect to Redis
    redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
    
    app = Flask(__name__)
    
    @app.route("/")
    def hello():
        try:
            visits = redis.incr("counter")
        except RedisError:
            visits = "<i>cannot connect to Redis, counter disabled</i>"
    
        html = "<h3>Hello {name}!</h3>" 
               "<b>Hostname:</b> {hostname}<br/>" 
               "<b>Visits:</b> {visits}"
        return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
    
    if __name__ == "__main__":
        app.run(debug=True, host='0.0.0.0', port=80)
    下面是个人的操作,WIn10电脑
    基于上面的Dockerfile requirements.txt app.py, 这三个文件, 都是刚在testA文件夹下
    cd testA docker build -t dockertest2 .
     // 创建dockertest2

      docker run -p 4000:80 dockertest2 // 运行dockertest2
       * Serving Flask app "app" (lazy loading)
       * Environment: production
         WARNING: Do not use the development server in a production environment.
         Use a production WSGI server instead.
       * Debug mode: on
       * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
       * Restarting with stat
       * Debugger is active!
       * Debugger PIN: 833-709-473
       192.168.99.1 - - [13/Jan/2019 09:51:43] "GET / HTTP/1.1" 200 -
       192.168.99.1 - - [13/Jan/2019 09:51:43] "GET /favicon.ico HTTP/1.1" 404 -

    
    
    浏览器输出: 
    (docker-machine ip => 192.168.99.100) // 查看本机的machine ip,
    http://192.168.99.100:4000/  // 浏览器输入这个地址就会显示,下面的页面
    
    
    
    docker ps -a  //显示本机的容器

      CONTAINER ID IMAGE        COMMAND        CREATED       STATUS       PORTS                NAMES
      c433122157a5 dockertest2 "python app.py" 5 minutes ago Up 5 minutes 0.0.0.0:4000->80/tcp loving_cray
      3557c16e1c72 fb687c8ae361 "/bin/sh -c 'pip ins…" 37 minutes ago Exited (2) 34 minutes ago objective_mcclintock
      26b08baff23f docker-whale "/bin/sh -c '/usr/ga…" About an hour ago Exited (0) About an hour ago nifty_blackwell
      8910cba61f67 docker/whalesay "cowsay xum" 2 hours ago Exited (0) 2 hours ago peaceful_brattain
      95594157df13 docker/whalesay "cowsay boo" 2 hours ago Exited (0) 2 hours ago wizardly_shannon
      5126e2358a7f hello-world "/hello" 2 hours ago Exited (0) 2 hours ago pedantic_wu

    
    
    docker stop c433122157a5 // 如果正在运行,可以停止 docker stop [CONTAINER ID]
    docker rm c433122157a5 // 删除此容器
    Docker 容器镜像删除
    1.停止所有的container,这样才能够删除其中的images:
    
    docker stop $(docker ps -a -q)
    
    如果想要删除所有container的话再加一个指令:
    
    docker rm $(docker ps -a -q)
    
    2.查看当前有些什么images
    
    docker images
    
    3.删除images,通过image的id来指定删除谁
    
    docker rmi <image id>
    
    想要删除untagged images,也就是那些id为<None>的image的话可以用
    
    docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
    
    要删除全部image的话
    
    docker rmi $(docker images -q)
  • 相关阅读:
    .NET基础篇——利用泛型与反射更新实体(ADO.NET Entity Framework)(转)
    反射奥秘
    ubuntu 安装chmsee
    ubuntu安装sublime,新立得
    Ubuntu 升级VisualBox后无法启动 Kernel driver not installed
    ubuntu安装stardict并导入词典
    PHP运行模式
    Ubuntu ibus输入法图标消失的解决办法
    MySQL 获得当前日期时间(以及时间的转换)
    mysql索引之or条件
  • 原文地址:https://www.cnblogs.com/xumBlog/p/10263526.html
Copyright © 2020-2023  润新知