{"id":433,"date":"2024-08-05T16:29:11","date_gmt":"2024-08-05T20:29:11","guid":{"rendered":"https:\/\/waterloobae.com\/?p=433"},"modified":"2025-08-20T14:29:20","modified_gmt":"2025-08-20T18:29:20","slug":"docker-setting-up-website-with-wordpress-docker-website-on-ssl","status":"publish","type":"post","link":"https:\/\/waterloobae.com\/blog\/2024\/08\/05\/docker-setting-up-website-with-wordpress-docker-website-on-ssl\/","title":{"rendered":"[Docker] Setting up website with WordPress Docker on SSL"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I used three images in my docker compose yaml file, They are mysql, wordpress and certbot. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. certbot from Let&#8217;s Encrypt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">certbot is image from Let&#8217;s Encrypt and it is free. The docker compose syntax looks as below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">    image: certbot\/certbot\n    container_name: certbot\n    volumes:\n      - .\/certbotdata:\/etc\/letsencrypt\n      - .\/webroot:\/var\/www\/html\n    command: certonly --webroot --webroot-path=\/xxx\/xxx\/xxxx --email john.doe@gmail.com --agree-tos --no-eff-email --force-renewal -d mysite1.com -d www.mysite1.com <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When containers are running. certbot container runs only once to generate your certificates. They can be found in .\/certbotdate\/live\/mysite1.com\/*. You can use them for Apache2 in WordPress container.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. WordPress <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once containers are up. Log into container shell to get two configuration files. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">docker exec -it &lt;container id or name&gt; \/bin\/bash<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">one for HTTP\/80 and another for HTTPS\/443. They can be found \/etc\/apache2\/sites-available and copy contents of them. After that you can create those two files in your local volume directory. Then, you can edit them as you need. You will need to change only two lines one for cert and another for private key. Then, you can add them into your docker compose volume like.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">volumes:\n  ........\n  - .\/apache_conf:\/etc\/apache2\/sites-available\n  - .\/certbotdata\/live\/waterloobae.com\/cert.pem:\/etc\/ssl\/certs\/cert.pem\n  - .\/certbotdata\/live\/waterloobae.com\/privkey.pem:\/etc\/ssl\/certs\/privkey.pem <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"> 3. Enabling SSL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress docker does not come up with SSL enabled. So, you will need to enable it with Dockerfile. MySQL and certbot can containerize from images. However, WordPress has to start with Dockerfile like.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">FROM wordpress:latest\nRUN apt-get update &amp;&amp; \\\napt-get install -y --no-install-recommends ssl-cert &amp;&amp; \\\nrm -r \/var\/lib\/apt\/lists\/*\nRUN a2enmod ssl &amp;&amp; \\\na2ensite default-ssl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I hope I&#8217;ve covered everything you need to know. Happy Dockering!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I used three images in my docker compose yaml file, They are mysql, wordpress and certbot. 1. certbot from Let&#8217;s Encrypt certbot is image from Let&#8217;s Encrypt and it is free. The docker compose syntax looks as below. When containers are running. certbot container runs only once to generate your certificates. They can be found [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-it-tips"],"_links":{"self":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":7,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions\/465"}],"wp:attachment":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}