使用Dockerfile制作LAMP环境镜像
编写Dockerfile
不修改默认页面
FROM centos:7
MAINTAINER "FOX"
COPY mysql.repo /etc/yum.repos.d/
COPY epel.repo /etc.yum.repos.d/
RUN yum clean all && yum makecache && yum install -y mysql-server php php-gd php-mysql httpd && \
sed -i "s/#ServerName www.example.com:80/ServerName www.example.com:80/" /etc/httpd/conf/httpd.conf
EXPOSE 80/tcp 3306/tcp
COPY start.sh /opt/
RUN chmod +x /opt/start.sh
CMD ["/opt/start.sh"]
修改默认页面
该Dockerfile在宿主机安装有GUI时通过浏览器可看出效果。文章来源:https://www.toymoban.com/news/detail-677039.html
FROM centos:7
MAINTAINER "FOX"
COPY mysql.repo /etc/yum.repos.d/
COPY epel.repo /etc.yum.repos.d/
RUN yum clean all && yum makecache && yum install -y mysql-server php php-gd php-mysql httpd && \
sed -i "s/#ServerName www.example.com:80/ServerName www.example.com:80/" /etc/httpd/conf/httpd.conf && \
echo "<?php phpinfo(); ?>" > /var/www/html/index.php
EXPOSE 80/tcp 3306/tcp
COPY start.sh /opt/
RUN chmod +x /opt/start.sh
CMD ["/opt/start.sh"]
Start Script
#!/bin/bash
/usr/sbin/httpd &
/usr/sbin/mysqld --user=mysql &
tail -f /dev/null
目录结构及文件
├── lamp
│ ├── Dockerfile
│ ├── epel.repo
│ ├── mysql.repo
│ └── start.sh
登录私有仓库
[root@docker lamp]# docker login www.kvm.cn
Authenticating with existing credentials...
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@docker lamp]# docker tag lamp:v1.1 www.kvm.cn/library/lamp:v1.1
上传镜像
[root@docker lamp]# docker push www.kvm.cn/library/lamp:v1.1
The push refers to repository [www.kvm.cn/library/lamp]
cc32351b5cc2: Pushed
516365b20893: Pushed
d0be8416d3fd: Pushed
acedef93300c: Pushed
174f56854903: Mounted from library/centos7
v1.1: digest: sha256:74d3d51a999ec3234febc5788018a8f46b58b02461f5e82b8e89268f3bb7b570 size: 1363
页面检查
文章来源地址https://www.toymoban.com/news/detail-677039.html
检测镜像可用性
[root@docker lamp]# docker run -d -it --name lamp --privileged=true lamp:v1.1 /usr/sbin/init
[root@docker lamp]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9dddfda70ce lamp:v1.1 "/opt/start.sh" 6 minutes ago Up 6 minutes 80/tcp, 3306/tcp lamp
[root@docker lamp]# curl 172.17.0.2
Web test
[root@docker lamp]# docker exec -it lamp /bin/bash
[root@4c13402c5313 /]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (start) since Tue 2023-08-22 17:36:44 UTC; 31s ago
到了这里,关于Dockerfile制作LAMP环境镜像的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!