从零docker-创建iTop4412开发环境

使用docker创建开发环境

Posted by Jerry Chen on November 11, 2019

注意,命令均在root账号下使用

1) 安装Docker

高版本Ubuntu输入如下,其他版本自行百度:

1
apt install docker.io

2) 启动Ubuntu:12.04容器

1
docker run -it --name first ubuntu:12.04 /bin/bash

安装vim

1
2
apt-get update
apt-get install vim

更换国内源

这里更新为网易源:

1
vim /etc/apt/sources.list

首先屏蔽原来文件中所有的项,然后在底部添加:

deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted

接着重新update:apt-get update

3) 安装sshd

1
2
apt-get install openssh-server
vim /etc/ssh/sshd_config

修改如下:

UsePAM yes 改为 UsePAM no
UsePrivilegeSeparation sandbox 改为 UsePrivilegeSeparation no

设置一个root密码:

1
passwd root

4) 提交容器副本

1
2
exit
docker commit -m="has update" -a="jerry" first myubuntu12:v1

在容器副本基础上开跑,并把容器内22端口映射到宿主机9022端口:

1
docker run -d --privileged -p 9022:22 --name u1204 myubuntu12:v1 /sbin/init

打开putty,选择ssh方式,IP地址填写宿主机IP(hostname -I 查看),端口填写9022。

下次启动的方式:

1
docker start u1204

5) 安装gcc等

以下在putty上操作:

1
apt-get install build-essential

1. 安装库

2. 降级GCC

3. 安装交叉编译器

4. 安装打包系统工具

6) 测试效果

新建hello.c文件:

1
2
3
4
5
#include <stdio.h>
int main(int argc, char *argv[]){
        printf("hello world!");
        return 0;
}

使用两种工具编译:

1
2
gcc hello.c -o hello_byGcc
arm-none-linux-gnueabi-gcc hello.c -o hello_byArm

查看产生的文件信息:

┌--------------------------------------------------------┐
│Command Prompt                                    - □ x │
├--------------------------------------------------------┤
│root@e99b029a518b:~# file hello_by*                     │
│hello_byArm: ELF 32-bit LSB executable, ARM, version 1  │
│(SYSV), dynamically linked (uses shared libs), for GNU  │
│/Linux 2.6.16, not stripped                             │
│hello_byGcc: ELF 64-bit LSB executable, x86-64, version │
│1 (SYSV), dynamically linked (uses  shared libs), for   │
│GNU/Linux 2.6.24, BuildID[sha1]=0xb7d7a94f7a3f198c24fc  │
│8208af5e8274fb5cfc78, not stripped                      │
└--------------------------------------------------------┘