dockerfile部署
准备工作
[root@docker ~]# mkdir -p /opt/apache/files
[root@docker ~]# cd /opt/apache/
[root@docker apache]# touch Dockerfile
[root@docker apache]# ls
dockerfile files
[root@docker apache]# tree
.
├── Dockerfile
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
└── httpd-2.4.51.tar.gz
编辑Dockerfile
编辑Dockerfile
[root@localhost apache]# vim Dockerfile
[root@localhost apache]# cat Dockerfile
FROM centos
LABEL MAINTAINER='jj 1264235309@qq.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/* &&\
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.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 \
--sysconfdir=/etc/httpd24 \
--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 &&\
sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
WORKDIR /usr/local/apache
EXPOSE 80
ENTRYPOINT /usr/local/apache/bin/apachectl -DFOREGROUND
[root@localhost apache]#
制作镜像
[root@localhost apache]# docker build -t tjf/httpd:v0.2 /opt/apache/
[root@localhost apache]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tjf/httpd v0.2 91444c5585f6 41 minutes ago 717MB
tjfyxy/httpd v0.3 91444c5585f6 41 minutes ago 717MB
ubuntu latest d2e4e1f51132 5 days ago 77.8MB
nginx latest fa5269854a5e 2 weeks ago 142MB
centos latest 5d0da3dc9764 7 months ago 231MB
测试
[root@localhost ~]# curl 192.168.183.137
<html><body><h1>It works!</h1></body></html>
添加标签
[root@localhost ~]# docker tag 91444c5585f6 tjfyxy/httpd:v0.3
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tjf/httpd v0.2 91444c5585f6 11 minutes ago 717MB
tjfyxy/httpd v0.3 91444c5585f6 11 minutes ago 717MB
ubuntu latest d2e4e1f51132 5 days ago 77.8MB
nginx latest fa5269854a5e 2 weeks ago 142MB
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: tjfyxy
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 push tjf/httpd:v0.2
The push refers to repository [docker.io/tjf/httpd]
8d399f030594: Preparing
fce9db8e1825: Preparing
74ddd0ec08fa: Preparing
denied: requested access to the resource is denied