官方文档:
安装docker:
https://docs.docker.com/install/linux/docker-ce/centos/
安装docker-compose:
https://docs.docker.com/compose/install/
# 所有docker命令映射都是:local:container# create container docker run --name <name> -p 123:123 -d <image> -v local_path:container_path# if failed, see logs docker logs <name/id># see how many docker containers docker ps -a# see networks docker network ls# see network detail docker network inspect <name/id># enter a container docker exec -ti <name/id> bash# start docker after rebooting docker start <name/id># check status docker stats [name/id]# delete container docker rm <name/id>docker container rm $(docker container ls -a -q) # Remove all containers# image docker build docker image ls -a # List all images on this machine docker image rm <image id> # Remove specified image from this machine docker image rm $(docker image ls -a -q) # Remove all images from this machine docker login # Log in this CLI session using your Docker credentials docker tag <image> username/repository:tag # Tag <image> for upload to registry docker push username/repository:tag # Upload tagged image to registry docker run username/repository:tag # Run image from a registry
docker run 命令解析:
https://www.runoob.com/docker/docker-run-command.html
学习:
https://docs.docker.com/get-started/part3/
docker-compose.yaml例子
version: '3' services:nginx:image: nginx:latest# 端口映射ports:- "80:80"# 依赖关系 先跑phpdepends_on:- "php"# 数据卷volumes:# 映射主机./conf.d目录到容器/etc/nginx/conf.d目录- "$PWD/conf.d:/etc/nginx/conf.d"- "$PWD/html:/usr/share/nginx/html"networks:- app_net# 容器名称container_name: "compose-nginx"php:build: ./php-mysqli# image指定build Dockerfile生成镜像的名称image: php:7.2-fpm-mysqliports:- "9000:9000"volumes:- "$PWD/html:/var/www/html"networks:- app_netcontainer_name: "compose-php"mysql:image: mysql:5.7ports:- "3306:3306"# 环境变量environment:# mysql密码- MYSQL_ROOT_PASSWORD={自己填密码}networks:app_net:# 固定子网ip,网段必须在子网络10.10.*.*ipv4_address: 10.10.10.1container_name: "compose-mysql" networks:# 配置docker networkapp_net:driver: bridgeipam:config:# 子网络- subnet: 10.10.0.0/16
docker-compose up