一文快速入门docker和nvidia-docker
docker search fastdfs
docker pull season/fastdfs:1.2
创建tracker目录,该目录用于和tracker进行目录挂载
sudo mkdir /opt/fastdfs/data/tracker
创建并启动tracker容器
sudo docker run -id --name tracker --restart=always --net host -v /etc/localtime:/etc/localtime -v /opt/fastdfs/data/tracker:/fastdfs/tracker/data season/fastdfs:1.2 tracker
创建storage目录,该目录存储上传的文件
sudo mkdir /opt/fastdfs/data/storage
创建并启动storage的容器
sudo docker run -id --name storage --restart=always --net host -v /etc/localtime:/etc/localtime -v /opt/fastdfs/data/storage:/fastdfs/store_path -e TRACKER_SERVER="192.168.20.99:22122" season/fastdfs:1.2 storage
将tracker容器中的客户端配置文件client.conf复制到宿主机,进行修改client.conf配置文件,
docker cp tracker:/etc/fdfs/client.conf /opt/fastdfs/data/tracker/
#将 client.conf
文件中 tracker_server的ip改为你linux服务器的ip
tracker_server=192.168.20.99:22122
再将拷贝到宿主机上的client.conf文件 复制回tracker容器
docker cp /opt/fastdfs/data/tracker/client.conf tracker:/etc/fdfs/
docker exec -it tracker bash
创建文件,执行命令
echo "zhangshoufu.com" >index.html
将文件上传到服务器,执行命令
fdfs_upload_file /etc/fdfs/client.conf index.html
创建nginx配置文件的文件夹
sudo mkdir /opt/fastdfs/data/nginx
将storage容器中的nginx配置文件拷贝到你创建的nginx文件夹下
docker cp storage:/etc/nginx/conf/nginx.conf /opt/fastdfs/data/nginx/
创建nginx的容器
sudo docker run -id --name fastdfs_nginx --restart=always -v /opt/fastdfs/data/storage:/fastdfs/store_path -v /opt/fastdfs/data/nginx/nginx.conf:/etc/nginx/conf/nginx.conf -p 8888:80 -e TRACKER_SERVER=192.168.20.99:22122 season/fastdfs:1.2 nginx
修改nginx的配置文件,部分内容修改如下
location /group1/M00 {
root /fastdfs/store_path/data;
ngx_fastdfs_module;
}
重启fastdfs_nginx容器
docker restart fastdfs_nginx
from fdfs_client.client import Fdfs_client, get_tracker_conf
# client.conf 为 tracker 容器中的 client.conf
client_conf = get_tracker_conf(r'client.conf')
client = Fdfs_client(client_conf)
ret = client.upload_by_filename('1.jpg')
result = str(ret['Remote file_id'], 'utf-8')
img_url = fastdfs_base_url + result
return img_url
参考:手把手教你docker搭建fastDFS文件上传下载服务器
参考:Docker 安装 Tomcat
docker pull tomcat
docker run --name tomcat --restart=always -p 8080:8080 -v /opt/soft/services/tomcat8.5/webapps:/usr/local/tomcat/webapps -d tomcat
Docker 安装 ActiveMQ
下载jupyter notebook
pip install jupyter notebook
ipython
from notebook.auth import passwd
passwd()
输完之后,设定一个密码,会生成一个sha1的秘钥会有如下的结果:
quit()
jupyter notebook --generate-config
这时候会生成配置文件,在 ~/.jupyter/jupyter_notebook_config.py
vim ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip='*'
# 目录
c.NotebookApp.notebook_dir = '/workspace'
# 上面生成的秘钥
c.NotebookApp.password = u'argon2:$argon2id$v=19$m=10240,t=10,p=8$B5b+4guljAwGmfDWR/Inmg$iWlSYIEQ+9ZxnibbUSsFJA'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8899
jupyter notebook --allow-root &
# 获取最新版本的 Docker 安装包 并安装
apt-get update
apt-get install -y docker.io
# 启动docker 后台服务
service docker start
#1:kafka需要zookeeper管理,所以需要先安装zookeeper。 下载docker pull wurstmeister/zookeeper:latest版本
docker pull wurstmeister/zookeeper
# 2:启动镜像生成容器
docker run -d --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime wurstmeister/zookeeper
# 3:下载kafka镜像
docker pull wurstmeister/kafka
# 4:启动kafka镜像生成容器
# -e KAFKA_BROKER_ID=0 在kafka集群中,每个kafka都有一个BROKER_ID来区分自己
# -e KAFKA_ZOOKEEPER_CONNECT=192.168.155.56:2181/kafka 配置zookeeper管理kafka的路径# 192.168.155.56:2181/kafka
# -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.155.56:9092 把kafka的地址端口注册给zookeeper
# -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 配置kafka的监听端口
# -v /etc/localtime:/etc/localtime 容器时间同步虚拟机的时间
docker run -d --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.155.56:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.155.56:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka
# 5:验证kafka是否可以使用
docker exec -it kafka /bin/sh
# 进入路径:/opt/kafka_2.11-2.0.0/bin下
# 运行kafka生产者发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic sun
# 发送消息
{"datas":[{"channel":"","metric":"temperature","producer":"ijinus","sn":"IJA0101-00002245","time":"1543207156000","value":"80"}],"ver":"1.0"}
# 6:运行kafka消费者接收消息
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic sun --from-beginning
下载离线包安装
1: 下载 链接:https://pan.baidu.com/s/1ggdvpGv 密码:rjtt
2: 解压后修改 server.properties 文件
broker.id=0
port=9092
host.name=192.168.25.175
advertised.host.name=192.168.25.175
log.dirs=自己创建一个log目录
num.partitions=2
zookeeper.connect=192.168.25.175
3: 启动 进入到 bin目录下
./kafka-server-start.sh …/config/server.properties &
4: 下载kafka-manager-1.0-SNAPSHOT.zip 链接:https://pan.baidu.com/s/1eTIEMK6 密码:0qf7
5: 解压后更改 application.conf
kafka-manager.zkhosts=“192.168.25.175”
6: 进入到 bin 目录下 启动
nohup kafka-manager -Dconfig.file=/usr/local/my-servers/kafka/kafka-manager-1.0/conf/application.conf >/dev/null 2>&1 &
# 搜索mysql
docker search mysql
# 拉取 mysal
docker pull mysql
# 运行mysql
docker run -itd --name mysql --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql
进入docker
mysql -u root -p
use mysql;
select user, host,plugin,authentication_string from user;
alter user 'root'@'%' identified with mysql_native_password by 'root';
dpkg --list|grep mysql
sudo apt-get remove mysql-common
sudo apt-get autoremove --purge mysql-server-5.7
dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
dpkg --list|grep mysql
sudo apt-get autoremove --purge mysql-apt-config
sudo apt-get update
sudo apt-get install mysql-server
mysql -uroot -p
show databases;
use mysql;
update user set authentication_string=PASSWORD("admin888.") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit;
如果不能远程访问,请按照下面操作
3. 开启远程访问
mysql -ur oot -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
#ok 退出MySQL 重启服务
mysql> quit;
$ service mysql restart
#发现客户端远程还是连接不上 继续修改mysql.cnf配置文件
#需要root权限,配置文件是只读的
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#往下翻,注释掉这一行,保存退出
# bind-address = 127.0.0.1
#重启服务
$ service mysql restart;
#ok 可以了
或者
#允许所有用户远程访问 修改用户名和密码为你自己的
mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
#允许单个ip 修改用户名和密码为你自己的
mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
#最后
mysql> FLUSH PRIVILEGES;
# 从主机复制文件到容器
sudo docker cp host_path containerID:container_path
# 从容器复制文件到主机
sudo docker cp containerID:container_path host_path
# 进入容器连接mysql,选择数据库,执行sql文件
mysql -u root -p
use mysql;
source /opt/a.sql
docker search redis
docker pull redis:latest
docker run -itd --name redis --restart=always -p 6379:6379 redis
docker run -d --name redis --restart=always -p 6378:6379 镜像地址 --requirepass 123456
docker exec -it redis-test /bin/bash
sudo snap install redis-desktop-manager
sudo docker pull nextcloud
sudo docker run -d --name nextcloud --restart=always -p 80:80 -v /opt/soft/geekplusa/nextcloud:/var/www/html nextcloud
参考:用docker部署RabbitMQ环境
sudo docker pull rabbitmq:management
sudo docker run -dit --name rabbitmq -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 rabbitmq:management
-d --name redis --restart=always -p 6378:6379 镜像地址
sudo docker pull docker.io/postgres
sudo docker run -d --name postgres --restart=always -v /opt/servers/postgresql/data:/var/lib/postgresql/data --privileged=true -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres
以Docker方式安装和配置Kong网关和Konga控制台
docker network create kong-net
# 拉取镜像
docker pull docker.io/postgres:9.6
# 启动PostgreSQL数据库
docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-v /opt/services/kong/db/pgdata:/var/lib/postgresql/data \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong" \
-e "POSTGRES_PASSWORD=kong" \
postgres:9.6
# 初始化数据
docker run --rm \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
kong:latest kong migrations bootstrap
创建配置文件/opt/services/kong/config/kong.yml
,内容如下
_format_version: "1.1"
services:
- name: admin-api
url: http://192.168.101.203:8001
routes:
- paths:
- /admin-api
plugins:
- name: key-auth
consumers:
- username: admin
keyauth_credentials:
- key: secret
docker run --rm \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
-v /opt/services/kong/config:/home/kong \
kong:latest kong config db_import /home/kong/kong.yml
docker pull docker.io/kong
docker run -d --name kong \
--network=kong-net \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 192.168.101.203:8001:8001 \
-p 192.168.101.203:8444:8444 \
kong:latest
http://192.168.101.203:8000/admin-api?apikey=secret
docker run -d --name konga-database \
--network=kong-net \
-p 5433:5432 \
-v /opt/services/kong/konga/postgres-data:/var/lib/postgresql/data \
-e "POSTGRES_USER=konga" \
-e "POSTGRES_DB=konga" \
-e "POSTGRES_PASSWORD=konga" \
postgres:9.6
/opt/services/kong/konga/postgres-data
文件夹,初始化数据库# 拉取konga镜像
docker pull pantsel/konga
# 初始化数据
docker run --rm \
--network=kong-net \
pantsel/konga:latest \
-c prepare \
-a "postgres" \
-u "postgres://konga:konga@konga-database:5432/konga"
docker run -d --name konga \
--network kong-net \
-e "TOKEN_SECRET=secret123" \
-e "DB_ADAPTER=postgres" \
-e "DB_URI=postgres://konga:konga@konga-database:5432/konga" \
-e "NODE_ENV=development" \
-p 1337:1337 \
pantsel/konga
http://192.168.101.203:1337
在Konga上,打开Connections,选择新建一个Kong连接。
选择连接类型为Kong Auth,输入连接名称、Loopback API URL和API Key。
systemcel stop docker
hostconfig.json
"PortBindings": {
"888/tcp": [
{
"HostIp": "",
"HostPort": "888"
}
],
"21/tcp": [
{
"HostIp": "",
"HostPort": "21"
}
]
}
config.v2.json
"ExposedPorts": {
"888/tcp": {},
"21/tcp": {}
}
"Ports": {
"888/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "888"
}
],
"21/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "21"
}
]
}
systemctl start docker
docker run -itd --name wxd_baai --restart=always -p 16000:6000 -p 16001:6001 -p 16002:6002 -v /opt/wxd/dockerfile/baai:/opt/models/baai 56fe0d666312
sudo docker run -itd -h mogu_blog_2 --name mogu_blog_2 -v /home/geekplusa/ai/datasets/docker/mogublog:/etc -p 11122:22 -p 15672:15672 -p 8600:8600 -p 9527:9527 -p 9528:9528 -p 16379:6379 -p 23306:3306 -p 10080:80 -p 8080:8080 -p 8601:8601 -p 8602:8602 -p 8603:8603 -p 8604:8604 -p 8605:8605 -p 8606:8606 -p 8607:8607 -p 5601:5601 -p 9411:9411 -p 465:465 -p 8848:8848 -p 8070:8070 moxi/mogu_blog_nacos
docker pull nacos/nacos-server
docker inspect mysql | grep IPAddress
docker run -d \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=172.17.0.3 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=root \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-p 8848:8848 \
--restart=always \
--name nacos \
nacos/nacos-server
sudo docker run \
--name nacos -d \
-p 8848:8848 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /home/geekplusa/ai/datasets/docker/nacos/logs:/home/nacos/logs \
-v /home/geekplusa/ai/datasets/docker/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties \
-v /home/geekplusa/ai/datasets/docker/nacos/data:/home/nacos/data \
nacos/nacos-server
custom.properties
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://172.17.0.5:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false
db.user=root
db.password=root
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.naming.expireInstance=true
docker run -itd --name wxd_pytorch_yolov5 --shm-size 8G -p 30010:6000 -p 30011:5000 -v /kolla/wxd/projects/yolo:/opt/projects/yolo 1caa84597263
sudo apt update
sudo apt install libglib2.0-dev
sudo apt install libgl1-mesa-glx
docker run -itd --name wxd_pytorch_yolov5 --shm-size 8G -p 30010:6000 -p 30011:5000 -v /opt/wxd/dockerfile/yolo:/opt/projects/yolo 869be8b6396a
sudo apt update
sudo apt install libglib2.0-dev
sudo apt install libgl1-mesa-glx
docker run -itd --name wxd_paddle_paddledet --shm-size 8G -p 30050:6000 -p 30051:5000 -v /opt/wxd/dockerfile/paddledetection:/opt/projects/paddledetection fb5bd3a2ad69
sudo apt update
sudo apt install libglib2.0-dev
sudo apt install libgl1-mesa-glx
docker run -itd --name wxd_pytorch_aigc --shm-size 8G -p 30020:6000 -p 30021:5000 -v /opt/wxd/dockerfile:/opt/projects 869be8b6396a
sudo apt update
sudo apt install libglib2.0-dev
sudo apt install libgl1-mesa-glx
docker: Error response from daemon: OCI runtime create failed: unable
to retrieve OCI runtime error (open
/run/containerd/io.containerd.runtime.v2.task/moby/ba8972872229c25598420b9597ba8de8de2033a788b7d2ec85ed97727d13baa7/log.json:
no such file or directory): exec: “nvidia-container-runtime”:
executable file not found in $PATH: : unknown.
解决
安装nvidia-docker
curl https://get.docker.com | sh && sudo systemctl --now enable docker
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo -E apt-get update
sudo -E apt-get install -y nvidia-docker2