docker-dev 镜像生成 踩过得坑
1、环境要求a GitHub accountgitmakedocker1、git 版本 大于 2.2.2vito@caas:~$ git --versiongit version 2.7.42、make版本 大于3.8.1vito@caas:~$ make -vGNU Make 4.1Built for x86_64-pc-linux-gnuCopyright (C) 1988-20
1、环境要求
a GitHub account
git
make
docker
1、git 版本 大于 2.2.2
vito@caas:~$ git --version
git version 2.7.4
2、make版本 大于3.8.1
vito@caas:~$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
3、docker 版本
vito@caas:~$ sudo docker --version
Docker version 17.09.0-ce, build afdb6d4
linux 用户小提示:
如果你的用户没有加入docker组,每次执行docker命令笔记加上sudo,执行下面的命令查看是否加入docker组,下面的命令表示没有加入。所以执行命令的时候必须加入sudo:
vito@caas:~$ getent group docker
docker:x:999:
vito@caas:~$ sudo docker --version
Docker version 17.09.0-ce, build afdb6d4
我们可以执行以下命令把当前用户加入到docker组:
(注意:执行命令后重新启动)
vito@caas:~$ sudo usermod -aG docker username
2、创建docker编译环境
- 首先下载docker源代码:https://github.com/docker/distribution.git
git clone https://github.com/docker/distribution.git
切换到源码根目录,发现根目录有一个Dockerfile,用这个Dockerfile创建docker的编译环境,执行创建docker
镜像的命令:
vito@caas:~/docker/moby$ sudo make BIND_DIR=. shell
Makefile:115: The docker client CLI has moved to github.com/docker/cli. For a dev-test cycle involving the CLI, run:
DOCKER_CLI_PATH=/host/path/to/cli/binary make shell
then change the cli and compile into a binary at the same location.
docker build -t "docker-dev:master" -f "" .
Sending build context to Docker daemon 38.42MB
Step 1/39 : FROM debian:stretch
---> 874e27b628fd
Step 2/39 : ARG APT_MIRROR=deb.debian.org
---> Using cache
---> 2189fccf5c85
Step 3/39 : RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list
---> Using cache
---> 183f018c0759
Step 4/39 : RUN apt-get update && apt-get install -y apparmor apt-utils aufs-tools automake bash-completion binutils-mingw-w64 bsdmainutils btrfs-tools build-essential cmake createrepo curl dpkg-sig gcc-mingw-w64 git iptables jq less libapparmor-dev libcap-dev libdevmapper-dev libnl-3-dev libprotobuf-c0-dev libprotobuf-dev libseccomp-dev libsystemd-dev libtool libudev-dev mercurial net-tools pkg-config protobuf-compiler protobuf-c-compiler python-backports.ssl-match-hostname python-dev python-mock python-pip python-requests python-setuptools python-websocket python-wheel tar thin-provisioning-tools vim vim-common xfsprogs zip --no-install-recommends && pip install awscli==1.10.15
---> Using cache
---> 65e6b480b2aa
Step 5/39 : ENV GO_VERSION 1.8.4
---> Using cache
---> fd97af8ee1ba
Step 6/39 : RUN curl -fsSL "https://studygolang.com/dl/golang/go${GO_VERSION}.linux-amd64.tar.gz" | tar -xzC /usr/local
---> Running in e405bfebb65e
踩过的坑
- 由于有些下载地址可能被屏蔽,中途的错误可以手动修改,改为国内下载地址,例如:golang的下载地址,各种版本都可以在这个地址找到:https://studygolang.com/dl,我们替换Dockerfile中的地址为国内地址:
- 再次执行 :sudo make BIND_DIR=. shell,执行到第30步的时候报错:
Step 30/39 : RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images buildpack-deps:jessie@sha256:85b379ec16065e4fe4127eb1c5fb1bcc03c559bd36dbb2e22ff496de55925fa6 busybox:latest@sha256:32f093055929dbc23dec4d03e09dfe971f5973a9ca5cf059cbfb644c206aa83f debian:jessie@sha256:72f784399fd2719b4cb4e16ef8e369a39dc67f53d978cd3e2e7bf4e502c7b793 hello-world:latest@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
---> Running in 73210ada3c34
/usr/bin/env: 'bash1\r': No such file or directory
The command '/bin/sh -c ./contrib/download-frozen-image-v2.sh /docker-frozen-images buildpack-deps:jessie@sha256:85b379ec16065e4fe4127eb1c5fb1bcc03c559bd36dbb2e22ff496de55925fa6 busybox:latest@sha256:32f093055929dbc23dec4d03e09dfe971f5973a9ca5cf059cbfb644c206aa83f debian:jessie@sha256:72f784399fd2719b4cb4e16ef8e369a39dc67f53d978cd3e2e7bf4e502c7b793 hello-world:latest@sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7' returned a non-zero code: 127
Makefile:115: recipe for target 'build' failed
make: *** [build] Error 127
经过分析是因为脚本中存在windows的换行符,使用命令替换掉换行符:
sed -i 's/\r$//' contrib/download-frozen-image-v2.sh
会把 .sh 中的\r 替换成空白,再次编译,pass
- 执行过程中,如果发现脚本中用到的有些文件夹不存在,可能是因为权限不够,造成创建的某些文件夹失败,解决方案是切换到root用户下执行:make BIND_DIR=. shell
- 镜像下载慢问题:由于sh脚本中定义的镜像仓库都是国外的仓库,下载镜像比较慢,甚至终端,可以把镜像仓库替换为国内的镜像仓库,例如:download-frozen-image-v2.sh文件中的registryBase
registryBase='https://registry-1.docker.io'
authBase='https://auth.docker.io'
authService='registry.docker.io'
替换为:
registryBase='https://5162s31v.mirror.aliyuncs.com'
authBase='https://auth.docker.io'
authService='registry.docker.io'
第33步错误:
Step 33/39 : RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
---> Running in 8f981ec52383
++ dirname /tmp/install-binaries.sh
+ . /tmp/binaries-commits
++ $'\r'
/tmp/binaries-commits: line 2: $'\r': command not found
The command '/bin/sh -c /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter' returned a non-zero code: 127
Makefile:115: recipe for target 'build' failed
make: *** [build] Error 127
解决办法1,修改/hack/dockerfile/install-binaries.sh文件
url=https://download.docker.com/linux/static
curl -Ls $url/$DOCKERCLI_CHANNEL/$arch/docker-$DOCKERCLI_VERSION.tgz | \
tar -xz docker/docker
mv docker/docker /usr/local/bin/
rmdir docker
改为:
url=https://download.docker.com/linux/static
curl -o docker-$DOCKERCLI_VERSION.tgz $url/$DOCKERCLI_CHANNEL/$arch/docker-$DOCKERCLI_VERSION.tgz | \
tar -xzf docker-$DOCKERCLI_VERSION.tgz
mv docker/docker /usr/local/bin/
rmdir docker
上马的方法如该不行,有个稍微麻烦的办法,自己下载docker-17.06.0-ce.tgz文件:https://download.docker.com/linux/static/edge/x86_64/docker-17.06.0-ce.tgz,解压缩,然后放在自己的github上,在github上自己的账户下创建public项目docker,把解压缩的文件上传到githua中。然后修改里面的语句为git clone,具体修改后内容如下:
url=https://download.docker.com/linux/static
git clone https://github.com/liujb0319/docker.git
mv docker/docker /usr/local/bin/
rm -rf docker
更多推荐
所有评论(0)