Conmi的正确答案——docker的基本指令与使用(非compose)
作者:互联网
平台:win10 20H2
docker版本:v20.10.6
1、搜索镜像
docker search mysql
2、拉取镜像
docker pull mysql
3、运行镜像(一般情况下)
docker run -itd --name testMysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -v D:\testMysqlLocalhostFile\mysql:/var/lib/mysql -v D:\testMysqlLocalhostFile\mysqlConf:/etc/mysql/conf.d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
命令的描述:
(-itd:像这些缩略却没有附加参数的命令可以连着使用)
(docker run --help中有列出这些指令,例如:-h, --hostname string 这种后面有string的意味着要追加一个字符串,则不建议连着使用,如果要使用,则在h后面追加地址的字符串,不然会报错)
-i:让容器的标准输入保持打开状态
-t:分配一个虚拟的终端
-d:在后台运行容器并打印容器ID
--name:为容器分配一个名称
-p:映射的端口号【“:”前面是本机的端口,“:”后面是容器的端口】
-e:设置环境变量
(mysql有三个环境变量:MYSQL_ROOT_PASSWORD、MYSQL_ALLOW_EMPTY_PASSWORD、MYSQL_RANDOM_ROOT_PASSWORD,必须设置任意一个,具体你的镜像有哪些需要自行查找)
-v:映射本地文件夹到容器【“:”前面是本机的文件夹,“:”后面是容器的文件夹】
(如果报错:“docker: Error response from daemon: status code not OK but 500...”,查看“https://www.kuke365.com/2020/02/15/docker-%E5%9C%A8windows%E4%B8%AD%EF%BC%8C%E6%98%A0%E5%B0%84%E6%97%B6%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%A2%B0%E5%88%B0%E9%94%99%E8%AF%AF/”)
mysql:latest:当前容器的镜像名以及版本(“:”前面是镜像名,“:”后面是版本)
【镜像名以及版本后面的内容解析:当前版本的docker如果不追加后续配置,“docker ps”会显示“docker-entrypoint.sh mysqld”,添加后则显示为"docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci",说明可以在后续追加mysql配置来实现mysql的其他执行模式】
4、插入新的命令到容器启动命令
docker update --restart always testMysql
能改的东西有限,端口这些一旦设置就不能修改的是不能用update来修改
5、列出网络
docker network ls
6、创建网络
docker network create testNetwork
7、查看网络信息
docker network inspect testNetwork
打印内容:
[
{
"Name": "testNetwork",
"Id": "4127fc3c4870caaccab95f6cc1ae22bc54eb0cb073fead394adb1daf8e0de08b",
"Created": "2021-06-09T05:08:35.7826929Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.21.0.0/16",
"Gateway": "172.21.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
8、容器连接到网络(容器间通讯)
docker network connect testNetwork testMysql
打印内容:
[
{
"Name": "testNetwork",
"Id": "4127fc3c4870caaccab95f6cc1ae22bc54eb0cb073fead394adb1daf8e0de08b",
"Created": "2021-06-09T05:08:35.7826929Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.21.0.0/16",
"Gateway": "172.21.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"0ba183cc126152897ae3e4c83ca6caa1dfe9a67c543f1668857794dffd108dfe": {
"Name": "testMysql",
"EndpointID": "6f7e40a309651af6f37f1ed24bf6b409d848f02b6b39eef6c71c069fa2422861",
"MacAddress": "02:42:ac:15:00:02",
"IPv4Address": "172.21.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
标签:容器,compose,false,Conmi,--,mysql,镜像,docker 来源: https://blog.csdn.net/fengwangzhe000/article/details/117732676