Dockerfile制作LAMP环境镜像

文章目录

使用Dockerfile制作LAMP环境镜像

编写Dockerfile

不修改默认页面

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时通过浏览器可看出效果。

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   && \
	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

shell 复制代码
#!/bin/bash
/usr/sbin/httpd &
/usr/sbin/mysqld --user=mysql &
tail -f /dev/null

目录结构及文件

复制代码
├── lamp
│   ├── Dockerfile
│   ├── epel.repo
│   ├── mysql.repo
│   └── start.sh

登录私有仓库

bash 复制代码
[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

给镜像打标签

bash 复制代码
[root@docker lamp]# docker tag lamp:v1.1 www.kvm.cn/library/lamp:v1.1  

上传镜像

bash 复制代码
[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

页面检查

检测镜像可用性

bash 复制代码
[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
相关推荐
chen94523 分钟前
EKS生产环境部署基于NLB的traefik网关
运维
淮北4941 小时前
linux系统学习(15.启动管理)
运维·服务器·网络·c++·vscode·学习
zml_20151 小时前
docker 1分钟 快速搭建 redis 哨兵集群
linux·redis·docker·docker-compose
运维开发王义杰2 小时前
Kubernetes: 解构Karpenter NodePool, 云原生时代的弹性节点管理艺术
云原生·容器·kubernetes
草履虫建模2 小时前
若依微服务一键部署(RuoYi-Cloud):Nacos/Redis/MySQL + Gateway + Robot 接入(踩坑与修复全记录)
redis·mysql·docker·微服务·云原生·nacos·持续部署
半梦半醒*2 小时前
playbook剧本
linux·运维·服务器·ssh·ansible·运维开发
大喵桑丶3 小时前
Nginx配置学习及多应用场景配置示例
运维·学习·nginx
wanhengidc3 小时前
七夕 云手机:浪漫时光里的科技陪伴
运维·科技·安全·游戏·智能手机
草莓田田圈~4 小时前
kubernetes-ubuntu24.04操作系统部署k8s集群
云原生·容器·kubernetes