创建自定义Ubuntu Docker镜像

之前体验过Ubuntu22.04版本后感觉新增的小工具很好用,就把几台linux设备都升级到了Ubuntu22,最近开发一个新功能,其中必须的编译依赖工具bcloud要求最高Ubuntu20下才能用,然后就悲催了,实在不想重装系统了,打算做一个ubuntu20+bcloud及依赖库的docker镜像,本文就记录下过程。

一、Dockerfile

我们先编写一个Dockerfile,以官方ubuntu:20.04为基础,安装基础库及编译依赖:

$ vim Dockerfile
FROM ubuntu:20.04
# install deepend lib
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y curl iputils-ping wget git git-lfs subversion screen vim tzdata cmake g++-9 python-dev libncurses5-dev uuid-dev
# install bcloud
RUN wget http://default.yanjingang.com/static/bcloud/client/install.sh
RUN /bin/bash install.sh
# install pip2
RUN wget -c https://bootstrap.pypa.io/pip/2.7/get-pip.py
RUN python2 get-pip.py
RUN pip install --no-binary=protobuf protobuf

二、构建镜像

登陆docker hub,使用Dockerfile创建镜像,并上传到docker hub方便其他机器使用:

$ vim create_docker_image.sh 

#!/bin/bash

# create docker image
docker login
docker image build -t yanjingang/ubuntu20:0.0.2 .
docker image ls
docker image push yanjingang/ubuntu20:0.0.2

三、使用镜像

1. 运行镜像容器,并挂载本地目录到容器内:

$ vim run_docker_container.sh 

#!/bin/bash

# run container
docker container run -it -v /home/mars/project:/home/mars/project --net=host yanjingang/ubuntu20 /bin/bash

2.容器内bcloud编译

source /root/.bashrc

cd /home/mars/project/abc
git config --global --add safe.directory /home/mars/project/abc
bcloud login-icode -u yanjingang -p Lx%2x   # need vpn env
bcloud local
make

 

yan 23.7.6

欢迎关注下方“非著名资深码农“公众号进行交流~

发表评论

邮箱地址不会被公开。