zoukankan      html  css  js  c++  java
  • docker简单示例

    参考链接:https://www.cnblogs.com/zhuyunbk/p/11661033.html

    docker 简单示例

    docker 安装

    sudo apt update
    
    sudo apt install -y docker.io
    

    切换国内源(没试过)

    切换成国内源,不然下载镜像很慢,例如个人切换成阿里的镜像源地址(去官网https://cn.aliyun.com/ 注册一下会有给一个源地址,下面这个是我申请的)

    或者使用 网易加速:"registry-mirrors": ["http://hub-mirror.c.163.com"]

    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
      "registry-mirrors": ["https://li8f2khr.mirror.aliyuncs.com"]
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    

    sudo docker pull nginx 从远程仓库下载nginx镜像

    =sudo docker pull nginx:latest 可以指定版本

    • sudo docker run -d -p 80:80 nginx 启动 后台 外部端口:内部端口
    • sudo docker ps 看现在正在运行的容器
    root@ubuntu:/home/likang/Desktop# docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
    0e9855777157        nginx               "nginx -g 'daemon of…"   12 minutes ago      Up 12 minutes       0.0.0.0:80->80/tcp   heuristic_golick
    
    
    • sudo docker exec -it 0e bash 进到容器里更改内容
    root@ubuntu:/home/likang/Desktop# docker exec -it 0e bash
    root@0e9855777157:/# cd /usr/share/nginx/html/
    root@0e9855777157:/usr/share/nginx/html# ls
    50x.html  index.html
    root@0e9855777157:/usr/share/nginx/html# cat index.html 
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
             35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    root@0e9855777157:/usr/share/nginx/html# echo hello > index.html 
    root@0e9855777157:/usr/share/nginx/html# cat index.html 
    hello
    
    
    • sudo docker commit 0e m1 将容器保存为镜像

      image-20200503150930055

    likang@ubuntu:~/Desktop$ sudo docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    nginx               latest              602e111c06b6        9 days ago          127MB
    hello-world         latest              bf756fb1ae65        4 months ago        13.3kB
    
    
  • 相关阅读:
    Flask入门到精通(二)
    MySQL安装配置,命令,异常纪要
    JQuery 选择器
    redhat Enterprise Linux Server release 7.2(Maipo) 安装redis-stat
    pssh 不能执行指定用户命令
    VMware 命令行下安装以及导入Ubuntu系统
    Linux CPU相关信息查看
    Ubuntu 16.04 Mxnet CPU 版本安装
    Ubuntu 16.04 TensorFlow CPU 版本安装
    <转>揭秘DNS后台文件:DNS系列之五
  • 原文地址:https://www.cnblogs.com/proper128/p/12825247.html
Copyright © 2011-2022 走看看