- dockerfile部署
- 编辑Dockerfile
- 制作镜像
- 上传镜像到dockerhub
准备工作
[root@localhost ~]# mkdir apache
[root@localhost ~]# cd apache
[root@localhost apache]# mkdir files
[root@localhost apache]# cd files/
[root@localhost files]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost files]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost files]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost apache]# tree
.
├── Dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
└── httpd-2.4.53.tar.gz
1 directory, 4 files
编辑Dockerfile
[root@localhost apache]# vim Dockerfile
[root@localhost apache]# cat Dockerfile
FROM centos
LABEL MAINTAINER='jiuyue 1@2.com'
ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.53
ADD files/* /usr/src/
RUN rm -rf /etc/yum.repos.d/*
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo &&
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo &&
yum -y install make gcc gcc-c++ openssl-devel pcre-devel expat-devel libtool libxml2-devel &&
useradd -r -M -s /sbin/nologin apache &&
cd /usr/src/apr-${apr_version} &&
sed -i '/$RM "$cfgfile"/d' configure &&
./configure --prefix=/usr/local/apr && make && make install &&
cd /usr/src/apr-util-${apr_util_version} &&
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&
make && make install &&
cd /usr/src/httpd-${httpd_version} &&
./configure --prefix=/usr/local/apache
--enable-so
--enable-ssl
--enable-cgi
--enable-rewrite
--with-zlib
--with-pcre
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/
--enable-modules=most
--enable-mpms-shared=all
--with-mpm=prefork && make && make install &&
rm -rf /var/log/* /var/cache/* /usr/src/* &&
dnf -y remove gcc gcc-c++ make
WORKDIR /usr/local/apache
EXPOSE 80
CMD ["-D","FOREGROUND"]
ENTRYPOINT ["/usr/local/apache/bin/apachectl']
制作镜像
[root@localhost ~]# docker build -t jiuyue99/httpd:latest apache/ [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jiuyue/httpd latest 3a47300e3d87 16 hours ago 717MB上传镜像到dockerhube10ac9c1306c 17 hours ago 231MB c0b8bc40ee00 17 hours ago 231MB httpd latest dabbfbe0c57b 4 months ago 144MB centos latest 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: jiuyue99 Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jiuyue/httpd latest 3a47300e3d87 16 hours ago 717MBe10ac9c1306c 17 hours ago 231MB c0b8bc40ee00 17 hours ago 231MB httpd latest dabbfbe0c57b 4 months ago 144MB centos latest 5d0da3dc9764 7 months ago 231MB [root@localhost ~]# docker tag jiuyue/httpd jiuyue99/httpd:0505 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jiuyue99/httpd 0505 3a47300e3d87 16 hours ago 717MB jiuyue/httpd latest 3a47300e3d87 16 hours ago 717MB e10ac9c1306c 17 hours ago 231MB c0b8bc40ee00 17 hours ago 231MB httpd latest dabbfbe0c57b 4 months ago 144MB centos latest 5d0da3dc9764 7 months ago 231MB [root@localhost ~]# docker push jiuyue99/httpd:0505 The push refers to repository [docker.io/jiuyue99/httpd] be9109f3ca37: Pushed 01fd6df81c8e: Mounted from library/busybox 042601: digest: sha256:f60d5819d04148e626a5c068c05f6991c86909eb4ef01b61b0aadcf9d903f50c size: 734



