# docker安装常用服务命令

# mysql

  • 数据相关目录: /var/lib/mysql

  • 配置文件目录: /etc/mysql/conf.d

在conf.d目录下新建配置文件mymy.cnf,配置文件的内容:

[mysqld]
sql_mode='NO_AUTO_VALUE_ON_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

[client]
default-character-set = utf8mb4
[client] 
default-character-set = utf8mb4
 
[mysql] 
default-character-set = utf8mb4
 
[mysqld]  
character-set-server = utf8mb4 
collation-server = utf8mb4_general_ci 

启动容器

docker run --name mysql5.7 --restart always -p 3306:3306 -v /etc/localtime:/etc/localtime:ro -v /data/mysql/datadir:/var/lib/mysql -v /data/mysql/conf.d:/etc/mysql/conf.d   -e MYSQL_ROOT_PASSWORD="root用户密码" -d mysql:5.7

# redis

# appendonly yes 开启持久化
# requirepass 登录密码
docker run --restart=always -p 6379:6379  --name myredis -v /data/redis/redis.conf:/etc/redis/redis.conf -v /data/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes --requirepass "redis密码"

# mongodb

#!/bin/bash
docker stop mongo
docker rm mongo
docker run --restart=always --name  mongo -v /etc/localtime:/etc/localtime:ro -v /data/mongodb0:/data/db -p 27017:27017 -d mongo  --auth

创建用户

docker    exec  -it  容器ID   /bin/bash     //进入容器

mongo  

use admin

db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})   //创建用户,此用户创建成功,则后续操作都需要用户认证
 
exit  
 
测试:
 
mongo  宿主机ip/admin  -utest -p
 
查看连接是否成功  

# nexus3

sudo docker run -d --name nexus3 --restart=always -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084  -v /data/nexus-data:/nexus-data sonatype/nexus3

映射的4个端口用途:

  • 8081:nexus3网页端

  • 8082:docker(hosted)私有仓库,可以pull和push

  • 8083:docker(proxy)代理远程仓库,只能pull

  • 8084:docker(group)私有仓库和代理的组,只能pull

访问网页端

  • http://ip:8081
  • 默认账号密码: admin/admin123

# gitlab

sudo docker run --detach \
    --hostname gitlab.example.com \
    --env GITLAB_OMNIBUS_CONFIG="external_url 'http://my.domain.com/'; gitlab_rails['lfs_enabled'] = true;" \
    --publish 9443:443 --publish 9090:80 --publish 9022:22 \
    --name gitlab \
    --restart always \
    -v /etc/localtime:/etc/localtime \
    --volume /data/gitlab/config:/etc/gitlab \
    --volume /data/gitlab/logs:/var/log/gitlab \
    --volume /data/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

# gogs

# Pull image from Docker Hub.
$ docker pull gogs/gogs

# Create local directory for volume.
$ mkdir -p /var/gogs

# Use `docker run` for the first time.
$ docker run --name=gogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs

# Use `docker start` if you have stopped it.
$ docker start gogs
Last Updated: 8/20/2020, 10:48:07 AM