# Betterlife Docker README
# 开发初步
搜索镜像[PHP]: docker search php
第一个docker应用: docker run hello-world
开始启动nginx: docker run --detach --publish=80:80 --name=webserver nginx
指定端口:docker run --name static-site -e AUTHOR="skygreen2001" -d -p 8888:80 dockersamples/static-site
开始启动ubuntu系统: docker run -it ubuntu bash
打开容器命令行工具 : docker exec -it brave_payne[容器名称] /bin/bash docker exec -it brave_payne[容器名称] /bin/sh
使用vi: apt-get update && apt-get install vim
使用ifconfig和ping: apt-get update && apt install net-tools && apt install iputils-ping
查看IP信息: docker inspect brave_payne[容器名称] | grep "IPAddress"
从容器拷贝文件到宿主机: docker cp 容器名:容器中要拷贝的文件名及其路径 要拷贝到宿主机里面对应的路径
- docker cp 17dbf5447e99:/usr/share/nginx/html/test.php /Users/master/Downloads/
从宿主机拷贝文件到容器: docker cp 宿主机中要拷贝的文件名及其路径 容器名:要拷贝到容器里面对应的路径
- docker cp /Users/master/Downloads/test.php 17dbf5447e99:/usr/share/nginx/html/
# 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
- Overview of Docker Compose (opens new window)
- Docker Compose (opens new window)
- Docker and Docker Compose (opens new window)
- 使用 docker-compose 构建你的项目 (opens new window)
- Deploying Laravel, Nginx, and MySQL with Docker Compose (opens new window)
- docker-compose搭建nginx+php+mysql (opens new window)
# 在IDE中使用Docker
- Docker in Visual Studio Code (opens new window)
- 所有Docker的指令操作: opening the Command Palette [⇧⌘P] and using Docker:
- Docker commands | Docker Explorer | Docker Compose
- Docker Explorer -> HELP AND FEEDBACK -> Open Docker Extension Walkthrough
- VSCode - Developing inside a Container (opens new window)
- VSCode - Create a development container (opens new window)
- VSCode - Remote development in Containers (opens new window)
- VSCode安装extension: Remote - Containers
- IDEA - Docker (opens new window)
- IDEA - 使用IDEA的Docker插件快速实现Docker镜像构建和部署 (opens new window)
# Docker开发
# PHP
安装PHP运行环境
- 实战多阶段构建 Laravel 镜像 (opens new window)
- 使用 Docker Compose 搭建了一套 LNMP 环境 (opens new window)
- 使用Docker部署LNMP+Redis环境 (opens new window)
- docker-php-ext-install.md (opens new window)
- Environment variables in Compose (opens new window)
- My Simple Approach to using Docker and PHP (opens new window)
- laravel-demo (opens new window)
安装PHP开发环境
- Laradock is a full PHP development environment based on Docker (opens new window)
- PHPDocker (opens new window)
- DevDock (opens new window)
- Docker Development Environment for PHP Apps (opens new window)
- Setting up PHP, PHP-FPM and NGINX for local development on DockerA primer on PHP on Docker under Windows 10 (opens new window)
# Kubernetes 初步
- 使用 Docker Desktop 可以很方便的启用 Kubernetes: https://yeasy.gitbook.io/docker_practice/setup/docker-desktop
- Docker Desktop for Mac/Windows 开启 Kubernetes (opens new window)