• docker官方 入门


    链接

    1.开始

    docker run -d -p 80:80 docker/getting-started
    docker ps #查看容器
    docker images #查看images
    docker inspect 容器#查看容器信息
    docker exec -it 容器 /bin/sh #交换进入容器
    ps 查看进程
    nginx位置 :etc/nginx
    nginx配置文件 nginx.conf conf.d/default.conf
    docker getting-started 位置: /usr/share/nginx/html/tutorial
    
    

    2、创建image

    • 复制app到usr/share/
    • 在app下构建Dockerfile
    FROM node:12-alpine
     WORKDIR /app
     COPY . .
     RUN yarn install --production
     CMD ["node", "src/index.js"]
    
    • 构建image

       docker build -t getting-started .
       docker images
       docker ps
       docker stop **
       docker ps
       docker run -dp 3000:3000 getting-started
       curl localhost:3000
       
       
      

    3、升级应用

    docker ps    #显示正在运行的容器
    docker ps -a #显示所有容器
    docker rm id #删除容器
    docker images #显示镜像
    docker rmi id #删除镜像
     docker build -t getting-started . #重新打包镜像
      docker run -dp 3000:3000 getting-started
    

    5 持久化数据(named volume)

     docker run -dp 3000:3000 getting-started
     docker ps
     docker stop id
     docker ps -a
     docker rm -f id
     docker volume create todo-db
     docker run -dp 3000:3000 -v todo-db:/etc/todos getting-started
     docker volume inspect todo-db
    

    6、use bind mounts

    #进入app目录
    docker run -dp 3000:3000    -w /app -v "$(pwd):/app"       node:12-alpine       sh -c "yarn install && yarn run dev"
    docker logs -f <container-id>
    
    

    7、多容器app 使用mysql

    • each container should do one thing and do it well
    docker network create todo-app
    
     docker run -d 
         --network todo-app --network-alias mysql 
         -v todo-mysql-data:/var/lib/mysql 
         -e MYSQL_ROOT_PASSWORD=secret 
         -e MYSQL_DATABASE=todos 
         mysql:5.7
         
     docker volume inspect todo-mysql-data
     docker ps
    docker exec -it <mysql-container-id> mysql -p
    
    mysql> SHOW DATABASES;
    
     docker run -it --network todo-app nicolaka/netshoot
     dig mysql
     
      docker run -dp 3000:3000 
       -w /app -v "$(pwd):/app" 
       --network todo-app 
       -e MYSQL_HOST=mysql 
       -e MYSQL_USER=root 
       -e MYSQL_PASSWORD=secret 
       -e MYSQL_DB=todos 
       node:12-alpine 
       sh -c "yarn install && yarn run dev"
       
       docker logs -f <container-id>
     
    

    8、使用 docker compose

    • 安装docker compose

      pip3 install --upgrade pip
      pip3 install docker-compose -i https://pypi.douban.com/simple
      docker-compose --version
      
    • 创建compose file

      vim docker-compose.yml
      #-------------
      version: "3.7"
      
      services:
        app:
          image: node:12-alpine
          command: sh -c "yarn install && yarn run dev"
          ports:
            - 3000:3000
          working_dir: /app
          volumes:
            - ./:/app
          environment:
            MYSQL_HOST: mysql
            MYSQL_USER: root
            MYSQL_PASSWORD: secret
            MYSQL_DB: todos
      
        mysql:
          image: mysql:5.7
          volumes:
            - todo-mysql-data:/var/lib/mysql
          environment: 
            MYSQL_ROOT_PASSWORD: secret
            MYSQL_DATABASE: todos
      
      volumes:
        todo-mysql-data:
        
        ####--------
        
      docker-compose up -d
      docker-compose logs -f
      
  • 相关阅读:
    elasticsearch设置共享目录、创建备份、恢复备份
    elasticsearch通过logstash去重数据
    Densite_RANK 函数
    Echarts立体地图加3D柱图可点击可高亮选中的开发
    Hadoop3.x-Yarn
    Hadoop3.x-MapReduce
    python dvwa时间盲注自动化脚本(level=low)
    python dvwa布尔盲注自动化脚本(level=low)
    时序数据库 Apache-IoTDB 源码解析之元数据索引块(六)
    网易2020校招笔试- 系统开发/研发工程师(提前批) [编程题]序列维护
  • 原文地址:https://www.cnblogs.com/hqzxwm/p/14534198.html
Copyright © 2020-2023  润新知