您好,登錄后才能下訂單哦!
[root@localhost ~]# yum install yum-utils device-mapper-persistent-data lvm2 -y
[root@localhost ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum install -y docker-ce
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service
[root@localhost ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://w1ogxqvl.mirror.aliyuncs.com"]
}
EOF
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker pull centos:7
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 5e35e350aded 6 weeks ago 203MB
[root@localhost ~]# cd /opt/
[root@localhost opt]# mkdir nginx
[root@localhost opt]# cd nginx/
[root@localhost nginx]# vim Dockerfile
#基于基礎鏡像
FROM 5e35e350aded
#用戶信息
MAINTAINER The is nginx <zjx>
#添加環境包
RUN yum install -y proc-devel gcc gcc-c++ zlib zlib-devel make openssl-devel wget
#下載nginx軟件包
RUN wget http://nginx.org/download/nginx-1.9.7.tar.gz
RUN tar zxvf nginx-1.9.7.tar.gz
#指定工作目錄
WORKDIR nginx-1.9.7/
RUN ./configure --prefix=/usr/local/nginx && make && make install
#指定http和https端口
EXPOSE 80
EXPOSE 443
#關閉守護進程
RUN echo "daemon off;" >>/usr/local/nginx/conf/nginx.conf
WORKDIR /root/nginx
#添加宿主機中run.sh到容器中
ADD run.sh /run.sh
RUN chmod 755 /run.sh
CMD ["/run.sh"]
[root@localhost nginx]# vim run.sh
#!/bin/bash
/usr/local/nginx/sbin/nginx
#創建新鏡像
[root@localhost nginx]# docker build -t nginx:new .
#啟動容器進行測試
[root@localhost nginx]# docker run -d -P nginx:new
1e42f3a46caf349a964c4304b900ecb406102e3dc7e5beae16293f071470e54b
[root@localhost nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e42f3a46caf nginx:new "/run.sh" 8 seconds ago Up 7 seconds 0.0.0.0:32769->80/tcp, 0.0.0.0:32768->443/tcp hardcore_cerf
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。