系统环境Archlinux,安装docker
sudo pacman -Suy
sudo pacman -S docker
加当前用户进docker组,设置docker开机启动,重启系统
sudo usermod -a -G $USER docker
sudo systemctl enable docker
sudo reboot
创建nginx的Dockerfile
FROM debian:stretch
ADD sources.list /etc/apt/
LABEL maintainer "admin@mail.com"
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends apt-utils && \
apt-get install -y --no-install-recommends nginx-full && \
rm -rf /var/lib/apt/lists/* && \
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
chown -R www-data:www-data /var/lib/nginx
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]
WORKDIR /etc/nginx
CMD ["nginx"]
EXPOSE 80
EXPOSE 443
在当前目录创建sources.list
nano sources.list
内容,根据自己所需要的源更改,要跟dockerfile里的系统和版本相同
deb http://mirrors.ustc.edu.cn/debian/ stretch main
deb-src http://mirrors.ustc.edu.cn/debian/ stretch main
deb http://mirrors.ustc.edu.cn/debian/ stretch-updates main
deb-src http://mirrors.ustc.edu.cn/debian/ stretch-updates main
deb http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main
deb-src http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main
deb http://mirrors.ustc.edu.cn/debian/ sid main
deb http://mirrors.ustc.edu.cn/debian/ stretch-backports main
开始编译
docker build -t nginx .
完成后运行
docker run --name web -p 8089:80 -d nginx
局域网任意一台机浏览器打开 http://当前主机ip:8089,就可以打开网页了。
网友评论