docker搭建工程编译环境

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 LinuxWindows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

docker主要用于构建隔离的标准化的运行环境,轻量级的PaaS(如dokku), 构建自动化测试和持续集成环境,以及一切可以横向扩展的应用。

Docker是基于Linux 64bit的,无法在32bit的linux/Windows/unix环境下使用

一、必要工具docker下载安装

1.1 下载安装docker工具

sudo apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt update

sudo apt-get install git docker docker-ce p7zip-full

sudo service docker start

1.2 添加当前用户到docker用户组

sudo usermod -aG docker <your-user-name>

例)sudo usermod -aG docker bwave

1.3 注销打开的终端会话,然后再次打开进入

1.4 检查docker是否安装完成

docker run hello-world
lb008@lb008:~/docker/11$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

二、docker pull 下载ubuntu镜像
参考文章:https://www.runoob.com/docker/docker-install-ubuntu.html

 

2.1 下载Ubuntu14.04 32bit镜像,执行命令:

从dockerhub上下载镜像

https://hub.docker.com/

https://docs.docker.com/engine/reference/commandline/pull/

docker pull i386/ubuntu:14.04

如果有错误,请参考以下两篇文章:

https://blog.csdn.net/BigData_Mining/article/details/87869147

https://www.cnblogs.com/python-wen/p/11224555.html

2.2 下载成功后,执行docker images查看

lb008@lb008:~/docker/11$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
32bit-ubuntu                              14.04               8b01d68827ff        9 months ago        186MB

     

 2.3 修改下载的Image的REPOSITORY和TAG属性

方法一:

执行命令docker tag <IMAGE ID> <REPOSITORY NAME>

lb008@lb008:~/docker/11$ docker tag 8b01d68827ff 32-ubuntu:14.04.06

 

 docker tag  <REPOSITORY>:<TAG>  <NEW REPOSITORY>:<NEW TAG>

docker tag 32bit-ubuntu:14.04 32-ubuntu:14.04.08

 查看

lb008@lb008:~/docker/11$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
i386/ubuntu                               14.04               8b01d68827ff        9 months ago        186MB
32-ubuntu                                 14.04.06            8b01d68827ff        9 months ago        186MB
32bit-ubuntu                              14.04               8b01d68827ff        9 months ago        186MB
32-ubuntu                                 14.04.08            8b01d68827ff        9 months ago        186MB

方法二:

2.3.1 创建一个新的文件夹11

2.3.2 在该文件夹下创建一个dockerfile文件,里面什么也不做

lb008@lb008:~/docker/11$ ls
Dockerfile

Dockerfile文件内容:

FROM i386/ubuntu:14.04

## Define DNS on your host
# /etc/docker/daemon.json => { "dns": [ "172.20.180.74", "172.20.180.23" ] } => sudo service docker restart
## Add Kernel build tools
#    bc kmod libncurses-dev
## Add utilities
#    bash-completion
## QtBagad
#    qtbase5-dev qt5-qmake
## Add Python packages
#    python-lxml python-pip python-setuptools python-wheel python3-pip python3-setuptools python3-wheel
## Wayland Host
# libxml2-dev

2.3.3 执行命令docker build

lb008@lb008:~/docker/11$ docker build -t 32bit-ubuntu:14.04 .
Sending build context to Docker daemon   2.56kB
Step 1/1 : FROM i386/ubuntu:14.04
 ---> 8b01d68827ff
Successfully built 8b01d68827ff
Successfully tagged 32bit-ubuntu:14.04
docker build 命令用于使用 Dockerfile 创建镜像。
语法

docker build [OPTIONS] PATH | URL | -

OPTIONS说明:

    --build-arg=[] :设置镜像创建时的变量;

    --cpu-shares :设置 cpu 使用权重;

    --cpu-period :限制 CPU CFS周期;

    --cpu-quota :限制 CPU CFS配额;

    --cpuset-cpus :指定使用的CPU id;

    --cpuset-mems :指定使用的内存 id;

    --disable-content-trust :忽略校验,默认开启;

    -f :指定要使用的Dockerfile路径;

    --force-rm :设置镜像过程中删除中间容器;

    --isolation :使用容器隔离技术;

    --label=[] :设置镜像使用的元数据;

    -m :设置内存最大值;

    --memory-swap :设置Swap的最大值为内存+swap,"-1"表示不限swap;

    --no-cache :创建镜像的过程不使用缓存;

    --pull :尝试去更新镜像的新版本;

    --quiet, -q :安静模式,成功后只输出镜像 ID;

    --rm :设置镜像成功后删除中间容器;

    --shm-size :设置/dev/shm的大小,默认值是64M;

    --ulimit :Ulimit配置。

    --tag, -t: 镜像的名字及标签,通常 name:tag 或者 name 格式;可以在一次构建中为一个镜像设置多个标签。

    --network: 默认 default。在构建期间设置RUN指令的网络模式

2.3.4 docker images查看重命令后信息

lb008@lb008:~/docker/11$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
32bit-ubuntu                              14.04               8b01d68827ff        9 months ago        186MB
i386/ubuntu                               14.04               8b01d68827ff        9 months ago        186MB
     

 

2.4 创建一个新的容器并运行该容器

docker run -d -i -t <image ID> /bin/bash

lb008@lb008:~/docker/11$ docker run -d -i -t 8b01d68827ff /bin/bash
803b3bcb8cb807d27f4ad531b2d72860775efda68e34cf91d1c7f4af2e1fa77e
docker run 语法
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS说明:

    -a stdin: 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项;

    -d: 后台运行容器,并返回容器ID;

    -i: 以交互模式运行容器,通常与 -t 同时使用;

    -P: 随机端口映射,容器内部端口随机映射到主机的端口

    -p: 指定端口映射,格式为:主机(宿主)端口:容器端口

    -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;

    --name="nginx-lb": 为容器指定一个名称;

    --dns 8.8.8.8: 指定容器使用的DNS服务器,默认和宿主一致;

    --dns-search example.com: 指定容器DNS搜索域名,默认和宿主一致;

    -h "mars": 指定容器的hostname;

    -e username="ritchie": 设置环境变量;

    --env-file=[]: 从指定文件读入环境变量;

    --cpuset="0-2" or --cpuset="0,1,2": 绑定容器到指定CPU运行;

    -m :设置容器使用内存最大值;

    --net="bridge": 指定容器的网络连接类型,支持 bridge/host/none/container: 四种类型;

    --link=[]: 添加链接到另一个容器;

    --expose=[]: 开放一个端口或一组端口;

    --volume , -v: 绑定一个卷

2.5 列出当前运行的容器信息

docker ps -a

lb008@lb008:~/docker/11$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
803b3bcb8cb8        8b01d68827ff        "/bin/bash"         7 seconds ago       Up 5 seconds                                   lucid_ganguly
f66ea9112379        hello-world         "/hello"            11 months ago       Exited (0) 11 months ago                       hopeful_allen
docker ps语法
docker ps [OPTIONS]

OPTIONS说明:

    -a :显示所有的容器,包括未运行的。

    -f :根据条件过滤显示的内容。

    --format :指定返回值的模板文件。

    -l :显示最近创建的容器。

    -n :列出最近创建的n个容器。

    --no-trunc :不截断输出。

    -q :静默模式,只显示容器编号。

    -s :显示总的文件大小。
$  docker ps # 查看所有正在运行容器
$  docker stop containerId # containerId 是容器的ID

$  docker ps -a # 查看所有容器
$  docker ps -a -q # 查看所有容器ID

$  docker stop $(docker ps -a -q) #  stop停止所有容器
$  docker  rm $(docker ps -a -q)  #  remove删除所有容器

 

2.6 进入创建的容器

docker exec -it <CONTAINER ID> /bin/bash

lb008@lb008:~/docker/11$ docker exec -it 803b3bcb8cb8 /bin/bash
root@803b3bcb8cb8:/# 
docker exec :在运行的容器中执行命令

语法

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

OPTIONS说明:

    -d :分离模式: 在后台运行

    -i :即使没有附加也保持STDIN 打开

    -t :分配一个伪终端

 

三、dockerfile安装docker编译环境

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值