How to install SSL on docker with PHP Centos

[[email protected] ~]# openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout server.key -out server.crt
Generating a 2048 bit RSA private key
.....................................................+++
...................................+++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:vmmysite
Email Address []:
[[email protected] ~]# ls
anaconda-ks.cfg dockerfileforphp server.crt server.key temp
[[email protected] ~]# mv server.crt docker.crt
[[email protected] ~]# mv server.key docker.key

vi ssl.conf

<VirtualHost vmmysite:443>

SSLEngine on
SSLCertificateFile /docker.crt
SSLCertificateKeyFile /docker.key

ServerAdmin [email protected]
DocumentRoot “/var/www/html/”
ServerName vmmysite
ServerAlias vmmysite
ErrorLog /var/www/html/error.log

<VirtualHost vmmysite:443>

Docker file code

from centos:7

run yum install -y httpd php php-mysqlnd mod_ssl openssl

run echo “” > /var/www/html/index.php

copy docker.crt /docker.crt
copy docker.key /docker.key
copy ssl.conf /etc/httpd/conf.d/default.conf

CMD [“apachectl”, “-D”, “FOREGROUND”]

Build an image from a Dockerfile
[[email protected] ~]# docker build -t ssldocker -f dockerfileforphp .
[[email protected] ~]# docker run –name ssldockerserver2 -d -p 443:443 ssldocker2

https://vmmysite/index.php

Leave a comment