新手问题 关于 docker 的问题

Awlter1 · February 24, 2020 · Last by wlon replied at February 26, 2020 · 3661 hits

https://docs.docker.com/compose/rails/ 我跟着这个教程发现卡在了 apt-get 上

这个把-pp 去掉后打印的打印

➜  assign_docker docker-compose run web rails new . --force --no-deps --database=postgresql
Starting assign_docker_db_1 ... done
Building web
Step 1/13 : FROM ruby:2.5
 ---> 2a14e515b307
Step 2/13 : RUN apt-get update && apt-get install -y nodejs postgresql-client
 ---> Running in 88acfd681acb
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://security.debian.org/debian-security buster/updates/main amd64 Packages [180 kB]
Get:4 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]

一直卡在这儿,Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7907 kB]

google 了下,docker build apt-get update stuck, 也没有合适的结果。。

代理开/关,全局/自动,各种情况都试过了。。

好像是网络哪里出问题了

试试在 apt-get update 前修改为国内的 debian mirror:

RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup
RUN printf "deb http://mirrors.aliyun.com/debian stretch main \ndeb http://mirrors.aliyun.com/debian stretch-updates main \ndeb http://mirrors.aliyun.com/debian-security stretch/updates main\n" | cat - /etc/apt/sources.list.backup > /etc/apt/sources.list

以上代码未在 docker 测试,仅供参考思路

@zhengpd 谢谢,不过换了 source 之后,还是要重新 get 原先 source 的 buster 然后就又卡住了

Reply to Awlter1

没留意到是 buster,你把 printf 那行的 stretch 全部替换成 buster 试试

@zhengpd 老样子😅

source 确实换了,但是还是卡住了

应该就是网络问题 设置一下命令行的 http_proxy 变量,再 docker build 试试。

FROM ruby:2.5

# 换源
RUN sed -i [email protected]@mirrors.tuna.tsinghua.edu.cn@g /etc/apt/sources.list
RUN sed -i [email protected]@mirrors.tuna.tsinghua.edu.cn@g /etc/apt/sources.list

RUN apt-get update && apt-get install -y nodejs postgresql-client

心血来潮,跟着教程试一试了。遇到了两个小坑(都有错误提示):

  1. 要自己手动安装 bundler
  2. postgres 指定密码或者使用 POSTGRES_HOST_AUTH_METHOD: 'trust'

还有就是源的问题也要考虑进去。

我的 sources.list

deb http://mirrors.163.com/debian/  stretch main non-free contrib
deb http://mirrors.163.com/debian/  stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/  stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/  stretch main non-free contrib
deb-src http://mirrors.163.com/debian/  stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/  stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/  stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/  stretch/updates main non-free contrib
You need to Sign in before reply, if you don't have an account, please Sign up first.