# Betterlife Docker README

# 开发初步

# Centos 安装 Docker

  • 安装lsof: yum install lsof (查看端口是否被占用)
  • Install Docker Engine on CentOS: https://docs.docker.com/engine/install/centos/
  • Configure Docker to start on boot: https://docs.docker.com/engine/install/linux-postinstall/
  • Play with Docker (PWD): https://labs.play-with-docker.com

# Ubuntu 安装 Docker

  • Install Docker Engine on Ubuntu: https://docs.docker.com/engine/install/ubuntu/
  • Configure Docker to start on boot: https://docs.docker.com/engine/install/linux-postinstall/
  • Play with Docker (PWD): https://labs.play-with-docker.com

# 常用指令

  • docker --help

  • 列出镜像: docker images

  • 删除1到多个镜像: docker rmi IMAGE_ID1 IMAGE_ID2

  • 查看最新前3个的container: docker ps -n 3

  • 查看所有的container(包括停止的): docker ps -a

  • 容器取名: docker container rename ef7b5043e9b4 bb

  • Docker stats for containers: docker stats

  • 开始一个container: docker start $CONTAINER_ID

    • 开始container: docker start $CONTAINER_NAME(docker run 需指定名称 --name $CONTAINER_NAME)
  • 关闭1到多个container: docker stop $CONTAINER_ID

    • 关闭container: docker stop $CONTAINER_NAME(docker run 需指定名称 --name $CONTAINER_NAME)
  • 删除1到多个container: docker rm $CONTAINER_ID1 $CONTAINER_ID2

  • 清理所有处于终止状态的容器: docker container prune

  • 删除所有容器的命令: docker rm -f docker ps -a | awk '{print $1}' | grep [0-9a-z]

  • 删除所有镜像的命令: docker rmi -f docker images | awk '{print $3}' | grep [0-9a-z] - docker rmi -f $(docker images | awk '/^/ { print $3 }')

  • 查看日志: docker logs -f [OPTIONS] CONTAINER

  • 查看文件变动: docker diff CONTAINER_ID

  • 创建镜像并上传

    • 安全检查: docker scan getting-started [image-name]
    • 检查创建中每层大小: docker image history getting-started [image-name]
    • 创建镜像: docker build -t getting-started [image-name] .
    • 运行创建的镜像: docker run -dp 3000:3000 getting-started [image-name]
    • 登录到docker hub: docker login -u [YOUR-USER-NAME]
    • 标记需提交的镜像:docker tag getting-started [image-name] YOUR-USER-NAME/getting-started [image-name]
    • 提交到hub: docker push YOUR-USER-NAME/getting-started [image-name]
    • hub上查询提交的镜像: https://hub.docker.com -> 搜索: YOUR-USER-NAME/getting-started
    • 如果本地已经存在,需要更新镜像: docker pull YOUR-USER-NAME/getting-started [image-name]
    • 运行推送的hub: docker run -dp 3000:3000 YOUR-USER-NAME/getting-started [image-name]
  • 创建一个数据卷: docker volume create my-vol

  • 查看所有的数据卷: docker volume ls

  • 查看数据卷信息: docker volume inspect my-vol

  • 删除数据卷: docker volume rm my-vol

  • 挂载数据卷: docker run -d -P --name web --mount source=my-vol,target=/usr/share/nginx/html nginx:alpine docker run -dp 82:80 -v my-vol:/usr/share/nginx/html nginx:alpine

  • 挂载主机目录: docker run -d -P --name web --mount type=bind,source=/Library/WebServer/Documents/,target=/usr/share/nginx/html nginx:alpine

  • 创建网络: docker network create todo-app

  • 网络列表: docker network list

  • docker-compose

    • Build or rebuild services: docker-compose build
    • 查看验证文件配置: docker-compose config
    • 后台启动: docker-compose up -d
    • List current running Containers: docker-compose ps
    • Close all running Containers: docker-compose stop
    • 删除Delete all existing Containers: docker-compose down
    • Compose查看日志: docker-compose logs -f

# Docker Compose

# 在IDE中使用Docker

# Docker开发

# PHP

# Kubernetes 初步