Dockerfile制作LAMP环境镜像

文章目录

    • 使用Dockerfile制作LAMP环境镜像
      • 编写Dockerfile
        • 不修改默认页面
        • 修改默认页面
      • Start Script
      • 目录结构及文件
      • 登录私有仓库
      • 给镜像打标签
      • 上传镜像
      • 页面检查
      • 检测镜像可用性

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

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 "" > /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

页面检查

Dockerfile制作LAMP环境镜像_第1张图片

检测镜像可用性

[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

你可能感兴趣的:(Docker,docker,运维,容器)