构建基于ubuntu的docker镜像时遇到的问题
问题描述
- 使用的dockerfile
FROM ubuntu RUN apt-get update && apt-get -y install vim
- 遇到的问题
E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 4d 3h 5min 47s). Updates for this repository will not be applied.
解决方案
同步时间 ntpdate ntp.aliyun.com
问题答案来自askubuntu
容器运行时的问题
nginx容器运行后,容器秒退
dockerfile内容
FROM ubuntu
RUN apt-get update && apt-get -y install nginx
原因
docker需要一个前台运行的程序,默认nginx在后台运行,所以容器会秒退
解决方案
将nginx提到前台运行
FROM ubuntu
RUN apt-get update && apt-get -y install nginx
CMD ["nginx", "-g", "daemon off;"]
附录
- 容器内的nginx也可以配置https访问,可以通过volume挂载,也可以把证书直接封到镜像中