dockerManual docker常用命令
作者:互联网
0 相关脚本
- 1 获取对应的镜像的所有历史版本: curl https://registry.hub.docker.com/v1/repositories/centos/tags
- 2
1 docker cli 命令镜像管理
1.1 常见命令https://docs.docker.com/engine/reference/commandline/docker/
命令 | 说明 |
---|---|
docker search myphp | grep admin | 搜索镜像 |
docker pull mysql:latest | |
docker run --name myMysql -it -d -p 30000:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql bash | -it: 进入终端(tty), -p 端口映射: 本机到容器, -d后台运行 |
docker ps -al | 查看镜像 |
docker rm -f 4e14 | 停止并完全删除镜像 |
docker logs -f --tail 50 myMysql | 查看日志 |
1.2 cli示例
这里给一个运行mysql的例子:(gitbash中运行)
docker run -d \
--rm --name myMysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-p 30000:3306 mysql --character-set-server=utf8mb4
2 docker yamlhttps://docs.docker.com/compose/gettingstarted/
2.1 这里给出redis和mysql的一个示例:
- 1 mysql:
version: '3.7'
services:
mysql:
image: mysql:8.0.18
restart: always
container_name: mysql
ports:
- "${MYSQL_PORT:-3306}:3306"
networks:
- ingress
environment:
- TZ=Asia/Shanghai
- MYSQL_DATABASE=fregata
- MYSQL_USER=xin
- MYSQL_PASSWORD=123
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-123456}
command:
--default-authentication-plugin=mysql_native_password
--character-set-server=utf8
--collation-server=utf8_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_connections=1000
--max_allowed_packet=128M;
volumes:
- ./volumes/data:/var/lib/mysql
- ./volumes/initdb.d:/docker-entrypoint-initdb.d:ro
networks:
ingress:
name: xin
- 2 reids:
version: "3.7"
services:
redis:
image: redis:5.0.7
build:
context: ./build
dockerfile: Dockerfile
container_name: redis
restart: always
environment:
- TZ=sia/Shanghai
ports:
- ${REDIS_PORT:-6379}:6379
volumes:
- ./volumes/data:/data
networks:
- ingress
networks:
ingress:
external:
name: xin
起\挺\查看容器:
docker-compose up -d
docker-compose down
docker-compose ls
标签:name,--,dockerManual,mysql,常用命令,volumes,MYSQL,docker 来源: https://blog.csdn.net/cxy_hust/article/details/120255895