我刚刚开始使用docker。
FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql php5-curl vim
RUN apt-get install apache2-utils
RUN apt-get clean
EXPOSE 89
CMD [“apache2ctl”, “-D”, “FOREGROUND”]
错误:
sudo docker build -t apache_image:1.0 --no-cache=true .
[sudo] password for pj:
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM ubuntu
---> 3b418d7b466a
Step 2/7 : RUN apt-get update
---> Running in 27548bc06017
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Err:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Ign:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Err:2 http://archive.ubuntu.com/ubuntu jammy InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Removing intermediate container 27548bc06017
---> 1ccdce33040e
Step 3/7 : RUN apt-get install apache2 curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql php5-curl vim
---> Running in 174722660b4f
Reading package lists...
E: Unable to locate package apache2
E: Unable to locate package curl
E: Unable to locate package apache2
E: Unable to locate package php5
E: Unable to locate package libapache2-mod-php5
E: Unable to locate package php5-mcrypt
E: Unable to locate package php5-mysql
E: Unable to locate package php5-curl
E: Unable to locate package vim
Building dependency tree...
Reading state information...
The command '/bin/sh -c apt-get install apache2 curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql php5-curl vim' returned a non-zero code: 100
pj@pj-virtual-machine:~/apache$
我做错了什么?
答案1
RUN apt-get update
RUN apt-get install ...
问题在于在单独的RUN
调用中运行这两个命令。合并为一个:
RUN apt-get update && apt-get install ...
参考:Stackoverflow 答案链接到 https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run自链接以来显然已经发生了变化,但答案包含引号。