15AH, San Francisco

California, United States.

Send Your Mail At:

tianyingkejishe@sina.cn

Working Hours

Mon-Sat: 9.30am To 7.00pm

【Ubuntu】dockers搭建编译环境

一、创建镜像

1、编写dockers配置文件

使用 dockerfile 创建容器,在容器中进行编译,完美解决编译环境问题,并且与主机环境隔离,互不影响。

首先在主机中安装 docker,请参考:安装教程

创建一个目录作为 docker 工作目录,例如~/docker/,在其中创建文件dockerfile,内容如下:

FROM ubuntu:18.04
MAINTAINER firefly "service@t-firefly.com"

ENV DEBIAN_FRONTEND=noninteractive

RUN cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
RUN sed -i 's@http://.*ubuntu.com@http://repo.huaweicloud.com@g' /etc/apt/sources.list

RUN apt update

RUN apt install -y build-essential crossbuild-essential-arm64 \
	bash-completion vim sudo locales time rsync bc python

RUN apt install -y repo git ssh libssl-dev liblz4-tool lib32stdc++6 \
	expect patchelf chrpath gawk texinfo diffstat binfmt-support \
	qemu-user-static live-build bison flex fakeroot cmake \
	unzip device-tree-compiler python-pip ncurses-dev python-pyelftools \
	subversion asciidoc w3m dblatex graphviz python-matplotlib cpio \
	libparse-yapp-perl default-jre patchutils swig expect-dev u-boot-tools

RUN apt update && apt install -y -f

# language support
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8

# switch to a no-root user
RUN useradd -c 'firefly user' -m -d /home/firefly -s /bin/bash firefly
RUN sed -i -e '/\%sudo/ c \%sudo ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
RUN usermod -a -G sudo firefly

USER firefly
WORKDIR /home/firefly

2、创建镜像

cd ~/docker
docker build -t sdkcompiler .
# sdkcompiler 是镜像名称,可随意更改,注意命令最后有一个‘.’
# 此过程需要一段时间,请耐心等待

二、创建容器

# 此处将主机内 SDK 所在文件夹挂载到容器内,这样容器内就能访问主机中的 SDK 了
# source= 填 SDK 所在目录;target= 填容器内的一个目录,必须是空目录
# ubuntu18 是容器名,firefly 是容器 hostname,均可随意更改
# sdkcompiler 是上一步的镜像名
docker run --privileged --mount type=bind,source=/home/fierfly/proj,target=/home/firefly/proj --name="ubuntu18" -h firefly -it sdkcompiler

三、退出容器、重启容器的方法

# 在容器内输入 exit 即可退出

# 查看所有容器(包括已退出的)
docker ps -a

# 重启一个退出的容器并连接
docker start ubuntu18 # 容器名
docker attach ubuntu18
anyShare分享到:
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。
stormwind