docker建立私有仓库

私有仓库其实也是个容器

  1. 拉取仓库镜像: docker pull registry
  2. 执行命令运行容器 docker run -itd -v /data/registry:/var/lib/registry -p 5000:5000 –restart=always –name registry registry:latest
  3. 查看是否运行 curl 127.0.0.1:5000/v2/_catalog 显示{“repositories”:[]} 显示成功

推送到私有仓库

  1. docker tag localImage:tag remoteRegistoryIP:port/image:tag
  2. docker push remoteRegistoryIP:port/image:tag

此时推送,会报错。docker 默认使用httrps推送,需要修改配置,支持http

  1. vim /etc/docker/daemon.json 没有需要创建
  2. 添加 { “insecure-registries”: [ “仓库的ip:仓库的端口”] }
  3. systemctl restart docker 重启docker
  4. 重新推送

执行docker images 查看 ,未找到刚才推送的镜像,需要从仓库中拉取到本地

在仓库中查看镜像 curl 127.0.0.1:5000/v2/_catalog 显示有数据

从私有仓库拉到本地 docker pull 127.0.0.1:5000/image:tag

执行docker images 查看, 此时有镜像了

docker mysql 没有 root 用户

docker mysql 没有 root 用户,需要创建 root

  1. flush privileges; 解决 ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute 这个问题
  2. CREATE USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123’;
  3. GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION;
  4. flush privileges;

docker 国内镜像

docker pull image 非常慢,需要加国内镜像

vim /etc/docker/daemon.json
## 填写以下内容
 {
    "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
 }

## 重启docker
systemctl restart docker

mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’ (Errcode: 13 – Permission denied)

在安装docker mysql:8.0版本时,出现错误:

mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’ (Errcode: 13 – Permission denied)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

ERROR: mysqld failed while attempting to check config
command was: “mysqld –verbose –help”

原因

因为Centos7安全Selinux禁止了一些安全权限,导致mysql和mariadb在进行挂载/var/lib/mysql的时候会提示如下信息

解决方法

在docker run中加入 –privileged=true 给容器加上特定权限

附上 MySQL 创建命令:

docker run –privileged=true –restart=always -itd –name mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=’123456′  -v /www/mysql/conf:/etc/mysql/conf.d -v /www/mysql/mysqldata:/var/lib/mysql  mysql –character-set-server=utf8mb4 –collation-server=utf8mb4_unicode_ci