一段时间不用docker后,发现对于一些基本命令都忘记了。。这里记录一下防止以后忘记
docker images查看所有本地主机上的镜像
docker search xxx查找镜像
docker pull xxx:version 拉取镜像,不加version即默认最新
docker run,--name 给容器一个别名;-v 目录映射,格式: <host目录>:<容器目录>;-d 后台运行容器;-p 端口映射,<主机端口>:<容器端口>;-e 指定容器中的环境变量
docker cp ,从容器中复制文件到主机,或者从主机复制文件到容器,用法 docker cp nacos:/home/nacos/logs /usr/local/nacos/ 从容器nacos里复制logs文件夹到主机的nacos文件夹下
docker ps查看运行的容器,-a即全部
docker inspect xxx 查看容器的元数据
docker rm xxx删除容器
start stop restart kill
docker exec -it xxx /bin/bash 进入xxx容器内部,开一个bash终端和容器交互
举个栗子,拿mysql来说,
拉取5.7版本的mysql镜像,docker pull mysql:5.7
docker run --name mysql -p 3306:3306 -v /usr/local/mysql/conf/:/etc/mysql -v /usr/local/mysql/log:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 ,运行mysql容器
再比如说拉取redis;docker pull redis,这里没加版本号那就默认拉去最新版镜像
docker run --name redis -p 6379:6379 -v /usr/local/redis/conf:/etc/redis -v /usr/local/redis/data:/data -d redis:latest,运行redis容器。
单机运行nacos容器
docker run --name nacos -p 8848:8848 -p 9848:9848 -p 9849:9849 -v /usr/local/nacos/conf/:/home/nacos/conf -v /usr/local/nacos/data/:/home/nacos/data -v /usr/local/nacos/logs/:/home/nacos/logs -e MODE=standalone -e JVM_XMS=256m -e JVM_XMX=256m -d nacos/nacos-server:v2.1.2
nginx
docker run --name nginx -p 80:80 -p 8080:8080 -v /usr/local/nginx/etc/:/etc/nginx/ -v /usr/local/nginx/log/:/var/log/nginx/ -d nginx
rocketmq安装,namesrv
docker run --restart=always --name namesrv --privileged=true -p 9876:9876 -v /usr/local/docker/rocketmq/logs:/root/logs -v /usr/local/docker/rocketmq/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" -d rocketmqinc/rocketmq sh mqnamesrv
rocketmq安装,broker
docker run --restart=always --name broker -p 10911:10911 -p 10909:10909 -v /usr/local/docker/rocketmq/logs:/root/logs -v /usr/local/docker/rocketmq/store:/root/store -v /usr/local/docker/rocketmq/conf:/opt/rocketmq-4.4.0/conf -d rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
顺便贴个broker的配置
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. brokerClusterName = DefaultCluster brokerName = 42_ip_broker brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH namesrvAddr = 127.0.0.1:9876 brokerIP1=127.0.0.1#对外暴露ip autoCreateSubscriptionGroup=true#生产关闭 cleanFileForciblyEnable=true storePathRootDir=/root/store storePathCommitLog=/root/store/commitlog
安装控制台
docker run -d --restart=always --name mqdash -e "JAVA_OPTS=-Drocketmq.namesrv.addr=ip:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8999:8080 pangliang/rocketmq-console-ng
ps:装载容器的路径建议自己亲自查看一下,毕竟有可能装的镜像都是不一样的