【docker】大佬指导dockerfile--20230220

原因:因为ubuntu的DNS被我错改了,所以下载docker会有问题。ubuntu本身的安装源不行哦。是我们连不到过去,网络不通。

解决方式:在镜像里改下安装源。

FROM python:3.8-slim
#RUN sed -i "40i  nameserver 8.8.8.8" /etc/resolv.conf
# RUN cat /etc/resolv.con
RUN sed -i "7i deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "8i deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "9i deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "10i deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "11i deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "12i deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "13i deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "14i deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "15i deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse" /etc/apt//sources.list
RUN sed -i "16i deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" /etc/apt//sources.list
RUN apt-get update -y && apt-get install gcc -y

COPY ./Django /code
WORKDIR /code/package

RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
RUN pip install uwsgi -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
EXPOSE 8000

RUN chmod 777 /code/package/runserver-docker.sh
RUN chmod 777 /code/package/start.sh


# Windows环境下编写的start.sh每行命令结尾有多余的\r字符,需移除。
RUN sed -i 's/\r//' ./start.sh

 
# 设置start.sh文件可执行权限
RUN chmod +x ./start.sh


CMD ["/bin/sh","/code/package/start.sh"]


前一次的指导过程

season@ZHS-190213650:~$ sudo su - root
[sudo] password for season:
/etc/update-motd.d/91-release-upgrade: 4: lsb_release: not found
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

  • Documentation: https://help.ubuntu.com
  • Management: https://landscape.canonical.com
  • Support: https://ubuntu.com/advantage

71 updates can be applied immediately.
27 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

This message is shown once a day. To disable it please create the
/root/.hushlogin file.
root@ZHS-190213650:~# systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down
root@ZHS-190213650:~# sudo apt-get install python3.8
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
python3.8-minimal
Suggested packages:
python3.8-venv python3.8-doc binfmt-support
The following NEW packages will be installed:
python3.8 python3.8-minimal
0 upgraded, 2 newly installed, 0 to remove and 30 not upgraded.
Need to get 0 B/2288 kB of archives.
After this operation, 6143 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Selecting previously unselected package python3.8-minimal.
(Reading database … 32299 files and directories currently installed.)
Preparing to unpack …/python3.8-minimal_3.8.10-0ubuntu1~20.04.6_amd64.deb …
Unpacking python3.8-minimal (3.8.10-0ubuntu1~20.04.6) …
Selecting previously unselected package python3.8.
Preparing to unpack …/python3.8_3.8.10-0ubuntu1~20.04.6_amd64.deb …
Unpacking python3.8 (3.8.10-0ubuntu1~20.04.6) …
Setting up python3.8-minimal (3.8.10-0ubuntu1~20.04.6) …
Setting up python3.8 (3.8.10-0ubuntu1~20.04.6) …
Processing triggers for man-db (2.9.1-1) …
Processing triggers for mime-support (3.64ubuntu1) …
root@ZHS-190213650:~# python
-bash: python: command not found
root@ZHS-190213650:~# pip
-bash: pip: command not found
root@ZHS-190213650:~# sudo apt-get install python3-pip
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
libexpat1-dev libpython3-dev libpython3-stdlib libpython3.8-dev python-pip-whl python3 python3-dev python3-distutils
python3-lib2to3 python3-minimal python3-pkg-resources python3-setuptools python3-wheel python3.8-dev zlib1g-dev
Suggested packages:
python3-doc python3-tk python3-venv python-setuptools-doc
The following NEW packages will be installed:
libexpat1-dev libpython3-dev libpython3-stdlib libpython3.8-dev python-pip-whl python3 python3-dev python3-distutils
python3-lib2to3 python3-minimal python3-pip python3-pkg-resources python3-setuptools python3-wheel python3.8-dev
zlib1g-dev
0 upgraded, 16 newly installed, 0 to remove and 30 not upgraded.
Need to get 86.7 kB/7558 kB of archives.
After this operation, 30.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 python3-minimal amd64 3.8.2-0ubuntu2 [23.6 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libpython3-stdlib amd64 3.8.2-0ubuntu2 [7068 B]
Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 python3 amd64 3.8.2-0ubuntu2 [47.6 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 libpython3-dev amd64 3.8.2-0ubuntu2 [7236 B]
Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 python3-dev amd64 3.8.2-0ubuntu2 [1212 B]
Fetched 86.7 kB in 2s (39.9 kB/s)
Selecting previously unselected package python3-minimal.
(Reading database … 32325 files and directories currently installed.)
Preparing to unpack …/python3-minimal_3.8.2-0ubuntu2_amd64.deb …
Unpacking python3-minimal (3.8.2-0ubuntu2) …
Selecting previously unselected package libpython3-stdlib:amd64.
Preparing to unpack …/libpython3-stdlib_3.8.2-0ubuntu2_amd64.deb …
Unpacking libpython3-stdlib:amd64 (3.8.2-0ubuntu2) …
Setting up python3-minimal (3.8.2-0ubuntu2) …
Selecting previously unselected package python3.
(Reading database … 32350 files and directories currently installed.)
Preparing to unpack …/00-python3_3.8.2-0ubuntu2_amd64.deb …
Unpacking python3 (3.8.2-0ubuntu2) …
Selecting previously unselected package python3-pkg-resources.
Preparing to unpack …/01-python3-pkg-resources_45.2.0-1ubuntu0.1_all.deb …
Unpacking python3-pkg-resources (45.2.0-1ubuntu0.1) …
Selecting previously unselected package libexpat1-dev:amd64.
Preparing to unpack …/02-libexpat1-dev_2.2.9-1ubuntu0.6_amd64.deb …
Unpacking libexpat1-dev:amd64 (2.2.9-1ubuntu0.6) …
Selecting previously unselected package libpython3.8-dev:amd64.
Preparing to unpack …/03-libpython3.8-dev_3.8.10-0ubuntu1~20.04.6_amd64.deb …
Unpacking libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.6) …
Selecting previously unselected package libpython3-dev:amd64.
Preparing to unpack …/04-libpython3-dev_3.8.2-0ubuntu2_amd64.deb …
Unpacking libpython3-dev:amd64 (3.8.2-0ubuntu2) …
Selecting previously unselected package python-pip-whl.
Preparing to unpack …/05-python-pip-whl_20.0.2-5ubuntu1.7_all.deb …
Unpacking python-pip-whl (20.0.2-5ubuntu1.7) …
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack …/06-zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb …
Unpacking zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) …
Selecting previously unselected package python3.8-dev.
Preparing to unpack …/07-python3.8-dev_3.8.10-0ubuntu1~20.04.6_amd64.deb …
Unpacking python3.8-dev (3.8.10-0ubuntu1~20.04.6) …
Selecting previously unselected package python3-lib2to3.
Preparing to unpack …/08-python3-lib2to3_3.8.10-0ubuntu1~20.04_all.deb …
Unpacking python3-lib2to3 (3.8.10-0ubuntu1~20.04) …
Selecting previously unselected package python3-distutils.
Preparing to unpack …/09-python3-distutils_3.8.10-0ubuntu1~20.04_all.deb …
Unpacking python3-distutils (3.8.10-0ubuntu1~20.04) …
Selecting previously unselected package python3-dev.
Preparing to unpack …/10-python3-dev_3.8.2-0ubuntu2_amd64.deb …
Unpacking python3-dev (3.8.2-0ubuntu2) …
Selecting previously unselected package python3-setuptools.
Preparing to unpack …/11-python3-setuptools_45.2.0-1ubuntu0.1_all.deb …
Unpacking python3-setuptools (45.2.0-1ubuntu0.1) …
Selecting previously unselected package python3-wheel.
Preparing to unpack …/12-python3-wheel_0.34.2-1ubuntu0.1_all.deb …
Unpacking python3-wheel (0.34.2-1ubuntu0.1) …
Selecting previously unselected package python3-pip.
Preparing to unpack …/13-python3-pip_20.0.2-5ubuntu1.7_all.deb …
Unpacking python3-pip (20.0.2-5ubuntu1.7) …
Setting up libexpat1-dev:amd64 (2.2.9-1ubuntu0.6) …
Setting up libpython3.8-dev:amd64 (3.8.10-0ubuntu1~20.04.6) …
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.5) …
Setting up python-pip-whl (20.0.2-5ubuntu1.7) …
Setting up libpython3-stdlib:amd64 (3.8.2-0ubuntu2) …
Setting up libpython3-dev:amd64 (3.8.2-0ubuntu2) …
Setting up python3 (3.8.2-0ubuntu2) …
running python rtupdate hooks for python3.8…
running python post-rtupdate hooks for python3.8…
Setting up python3-wheel (0.34.2-1ubuntu0.1) …
Setting up python3.8-dev (3.8.10-0ubuntu1~20.04.6) …
Setting up python3-lib2to3 (3.8.10-0ubuntu1~20.04) …
Setting up python3-pkg-resources (45.2.0-1ubuntu0.1) …
Setting up python3-distutils (3.8.10-0ubuntu1~20.04) …
Setting up python3-setuptools (45.2.0-1ubuntu0.1) …
Setting up python3-dev (3.8.2-0ubuntu2) …
Setting up python3-pip (20.0.2-5ubuntu1.7) …
Processing triggers for man-db (2.9.1-1) …
root@ZHS-190213650:~# pip list
Package Version


pip 20.0.2
setuptools 45.2.0
wheel 0.34.2
root@ZHS-190213650:~# pip install django3.2.7
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))’: /simple/django/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))’: /simple/django/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))’: /simple/django/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))’: /simple/django/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProtocolError(‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))’: /simple/django/
ERROR: Could not find a version that satisfies the requirement django
3.2.7 (from versions: none)
ERROR: No matching distribution found for django==3.2.7
root@ZHS-190213650:~# sudo systemctl restart docker
root@ZHS-190213650:~# cd myseason
-bash: cd: myseason: No such file or directory
root@ZHS-190213650:~# ls
root@ZHS-190213650:~#

[‎2023/‎2/‎10 9:21]
jason,你最近有用docker打镜像吗

系統已儲存此交談。您很快就會在商務用 Skype 的 [交談] 索引標籤及 Outlook 的 [交談記錄] 資料夾中看見該內容。
[‎2023/‎2/‎10 9:36] Jason Sy Li/WZS/Wistron:
没有,请问什么事呢?

[‎2023/‎2/‎10 9:36]
[‎2023/‎2/‎10 9:02]
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f980f3c12e0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /simple/django/

docker build -t seasonzhang/training_dashboard:2.1.1 .
用这个指令的时候,出错了。
然后改了镜像源也不行

[‎2023/‎2/‎10 9:38]
windows本地可以下载,但是在ubuntu里面的docker里面下载不了

[‎2023/‎2/‎10 9:41] Jason Sy Li/WZS/Wistron:
sudo iptables -t filter -F
sudo iptables -t filter -X
systemctl restart docker
试试

[‎2023/‎2/‎10 9:41]

season@ZHS-190213650:~$ sudo iptables -t filter -F
season@ZHS-190213650:~$ sudo iptables -t filter -X
season@ZHS-190213650:~$ systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down

[‎2023/‎2/‎10 9:47] Jason Sy Li/WZS/Wistron:
你这是微软自带的那个吗

[‎2023/‎2/‎10 9:48]
是的
windows下面装了WSL2

[‎2023/‎2/‎10 9:48] Jason Sy Li/WZS/Wistron:
你sudo su - root
再执行最后一条

[‎2023/‎2/‎10 9:49]
無標題
season@ZHS-190213650:~$ sudo su - root
[sudo] password for season:
/etc/update-motd.d/91-release-upgrade: 4: lsb_release: not found
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

  • Documentation: https://help.ubuntu.com
  • Management: https://landscape.canonical.com
  • Support: https://ubuntu.com/advantage

71 updates can be applied immediately.
27 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

This message is shown once a day. To disable it please create the
/root/.hushlogin file.
root@ZHS-190213650:~# systemctl restart docker
System has not been booted with systemd as init system (PID 1). Can’t operate.
Failed to connect to bus: Host is down
root@ZHS-190213650:~#

[‎2023/‎2/‎10 9:49]
不知道为啥

[‎2023/‎2/‎10 9:51] Jason Sy Li/WZS/Wistron:
sudo apt install systemctl 这个呢?

[‎2023/‎2/‎10 9:52]
sudo apt install systemctl 这个呢? 这个是成功安装的
我感觉是虚拟机的DNS有问题

[‎2023/‎2/‎10 9:53] Jason Sy Li/WZS/Wistron:
systemctl restart docker
再试试
这个和DNS没关系。。。。

[‎2023/‎2/‎10 9:53]
加了systemctl restart docker
sudo systemctl restart docker

[‎2023/‎2/‎10 9:54] Jason Sy Li/WZS/Wistron:
可以吗

[‎2023/‎2/‎10 9:56]
用root进去还是season进去?
docker build -t seasonzhang/training_dashboard:2.1.1 .

[‎2023/‎2/‎10 9:56] Jason Sy Li/WZS/Wistron:
都可以吧

[‎2023/‎2/‎10 9:57]
上面的指令是重启了docker对吗
好像还是不行

[‎2023/‎2/‎10 9:57]
無標題
season@ZHS-190213650:~/myseason/myfile/training_dashboard-20230209-2.1.1-Y23培训需求看板$ docker build -t seasonzhang/training_dashboard:2.1.1 .
Sending build context to Docker daemon 8.399MB
Step 1/12 : FROM python:3.8-slim
—> b0d55d04540d
Step 2/12 : RUN apt-get update -y && apt-get install gcc -y
—> Using cache
—> 8728353283d6
Step 3/12 : COPY ./Django /code
—> Using cache
—> 8b5c5c41b9f2
Step 4/12 : WORKDIR /code/package
—> Using cache
—> 07e1958bbf32
Step 5/12 : RUN pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
—> Running in f9a5ae6c22c4
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f7226c685e0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)': /pypi/simple/django/

[‎2023/‎2/‎10 9:57]
我怀疑是网络问题
但是windows本机的网络是好的
ubuntu里面的网络估计有问题

[‎2023/‎2/‎10 9:59] Jason Sy Li/WZS/Wistron:
你输这一句试试echo “nameserver 8.8.8.8” | tee /etc/resolv.conf > /dev/null
然后再打包一下

[‎2023/‎2/‎10 10:00]
season@ZHS-190213650:~/myseason/myfile/training_dashboard-20230209-2.1.1-Y23培训需求看板$ ping https://www.baidu.com/
ping: https://www.baidu.com/: Name or service not known
season@ZHS-190213650:~/myseason/myfile/training_dashboard-20230209-2.1.1-Y23培训需求看板$ echo “nameserver 8.8.8.8” | tee /etc/resolv.conf > /dev/null
-bash: tee /etc/resolv.conf: No such file or directory
-bash: echo nameserver 8.8.8.8 : command not found
我发现我ping不到百度

[‎2023/‎2/‎10 10:01] Jason Sy Li/WZS/Wistron:
晚点再找你,我开个会先。不好意思

[‎2023/‎2/‎10 10:02]
你先开会吧
谢谢啦

系統已儲存此交談。您很快就會在商務用 Skype 的 [交談] 索引標籤及 Outlook 的 [交談記錄] 資料夾中看見該內容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值