qemu
简介
最近在项目中需要编译arm架构的某驱动docker镜像,但是手头上没有现成的arm架构的机器环境,于是在网上搜索了下如何在x86机器模拟arm环境来进行编译。我找到了一款神器:multiarch/qemu-user-static
项目地址:https://github.com/multiarch/qemu-user-static
qemu-user-static是一个用于利用当前操作系统来运行其它架构的一个仿真器,这个github项目可以通过x86的机器编译出其它各个架构的docker镜像。
支持的指令集架构:
armv7l
ppc64le
s390x
aarch64
armv7l
ppc64le
安装qemu
#更新apt源 |
验证和配置docker
拉取arm镜像docker pull --platform arm64 ubuntu
试运行uname -m # 显示主机架构
#x86_64
docker run --rm -t arm64v8/ubuntu uname -m # 在x86_64上运行为aarch64编写的可执行文件
#standard_init_linux.go:211: exec user process caused "exec format error"
显示报错
配置qemu,重新运行
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes # 这一步将执行注册脚本(docker+qemu功能) |
显示运行成功
yml创建ldap-mysql
1.编写yml
创建 compose.ymlvim one_dir/compose.yml
填入以下内容version: '2'
services:
db:
image: mysql:latest
platform: arm64
volumes:
- "./.data/db:/var/lib/mysql"
- "./conf/mysql:/etc/mysql/conf.d"
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ldap
MYSQL_DATABASE: ldap
MYSQL_USER: vives
MYSQL_PASSWORD: ldap
ldap-client:
image: osixia/phpldapadmin:latest
platform: arm64
hostname: vivesdata
domainname: ldap.vives.be
depends_on:
- db
- ldap
links:
- db
- ldap:ldap.vives.be
ports:
- 6443:443
restart: always
environment:
LDAP_DB_HOST: db:3306
LDAP_DB_PASSWORD: ldap
LDAP_DB_USER: vives
LDAP_DB_NAME: ldap
PHPLDAPADMIN_LDAP_HOSTS: ldap.vives.be
PHPLDAPADMIN_LDAP_CLIENT_TLS: "false"
ldap:
depends_on:
- db
image: osixia/openldap:latest
platform: arm64
hostname: vivesdata
domainname: ldap.vives.be
ports:
- "389:389"
volumes:
- "./.data/var/lib/ldap:/var/lib/ldap"
- "./.data/etc/ldap/slapd.d:/etc/ldap/slapd.d"
links:
- db
restart: always
environment:
LDAP_DB_HOST: db:3306
LDAP_DB_PASSWORD: ldap
LDAP_DB_USER: vives
LDAP_DB_NAME: ldap
LDAP_ORGANISATION: Vives
LDAP_DOMAIN: ldap.vives.be
LDAP_ADMIN_PASSWORD: ldap
LDAP_TLS: "false"
ldapbackup:
depends_on:
- db
- ldap
image: osixia/openldap-backup:latest
platform: arm64
hostname: vivesdata
domainname: ldap.vives.be
#volumes:
# - "./.data/openldap/backup:/data/backup"
# - "./.data/etc/ldap/slapd.d:/etc/ldap/slapd.d"
links:
- db
- ldap:ldap.vives.be
restart: always
environment:
LDAP_DB_HOST: db:3306
LDAP_DB_PASSWORD: ldap
LDAP_DB_USER: vives
LDAP_DB_NAME: ldap
LDAP_ORGANISATION: Vives
LDAP_DOMAIN: ldap.vives.be
LDAP_ADMIN_PASSWORD: ldap
LDAP_BACKUP_CONFIG_CRON_EXP: "0 5 * * *"
LDAP_BACKUP_DATA_CRON_EXP: "0 5 * * *"
2.运行
进入刚刚创建的文件的路径下
cd one_dir/ |
运行一下命令创建环境docker-compose up
如果报错,可以看看是不是没有权限的错误,如果是则加sudo
运行
进入 ldap container:docker-compose exec ldap /bin/bash
运行示例ldapsearch -x -h localhost -b dc=ldap,dc=vives,dc=be -D "cn=admin,dc=ldap,dc=vives,dc=be" -w ldap
以下为输出示例# extended LDIF
#
# LDAPv3
# base with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
[...]
# numResponses: 3
# numEntries: 2
PhpLdapAdmin in webbrowser openen op host:https://localhost:6443
login: cn=admin,dc=ldap,dc=vives,dc=be psw: ldap
允许远程mysql连接
2.进入mysql容器
两种方式,普通进入方式,my_db为创建的Mysql的容器名字,可通过 docker ps
查看docker exec -it my_db /bin/bash
docker-compose方式进入docker-compose exec db /bin/bash
2.进入mysql
mysql -uroot -p |
2.修改权限
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; ### 123456 mysql的登录密码 |
导出镜像,并在目标设备导入
导出
docker save -o ldap_images.tar osixia/openldap-backup:latest osixia/phpldapadmin:latest osixia/openldap:latest mysql:latest |
在目标设备导入
docker load -i <image_name>.tar |
将compose.yml复制到目标设备,运行
docker-compose up |