Docker笔记

常用命令

docker start 02ee30fa0053
docker stop 02ee30fa0053
docker rm 02ee30fa0053
docker ps -a
docker exec -it 02ee30fa0053 bash
docker-compose run --service-ports some-db

发现之前用docker run会连不上redis和MySQL,但是用docker-compose之后就可以了,很是奇怪

MySQL

docker-compose

some-mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: password
ports:
- "3306:3306"

从内部命令行连接

docker exec -it 02ee30fa0053 bash
mysql -u root -p

用DataGrip之前似乎需要先用命令行创建一个database再连接

create database test;
show databases;

参考

https://hub.docker.com/_/mysql/

Redis

docker-compose

some-redis:
image: redis
ports:
- "6379:6379"

参考

https://hub.docker.com/_/redis/