Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run docker service on HTTPS

Currently, I run a simple docker container by using the following files.

DockerFile

FROM microsoft/aspnet:4.7.1 WORKDIR /inetpub/wwwroot EXPOSE 80 COPY index.html . 

docker-compose.yml

version: '3.4'  services:  testapp:   image: mytestapp:${TAG:-latest} build:   context: .   dockerfile: Dockerfile 

docker-compose.override.yml

version: '3.4'  services:   testapp:    ports:     - "9091:80" 

I use windows image to create my container by using the following command and I can access it by http://localhost:9091/.

docker-compose -f docker-compose.yml -f docker-compose.override.yml build 

I want to access my app by using HTTPS instead of http.

What are the steps that I need to follow ?

like image 801
marvelTracker Avatar asked Jun 12 '18 06:06

marvelTracker


People also ask

Does Docker use http or https?

By default docker use https to connect to docker registry. But there can be use cases to use insecure registry.

How do you expose Docker daemon without TLS?

If you are using Docker Desktop and want to connect through the TCP socket, enable the Expose daemon on tcp://localhost:2375 without TLS option in the General section of your Docker settings. Then set Engine API URL to tcp://localhost:2375 .


1 Answers

Thanks Jerome for the answer. I did the following things to get https working on my container. I hope this might be helpful to someone.

This image has IIS on it.

  1. Add Self signed certificate to image from this script:

certificate.ps1

  1. Create Self Signed Certificate.
  2. Install it on local certificate store.
  3. Create HTTPs Binding and add the generated SelfSign Certificate to the default Web site which has my web application
import-module webadministration  cd cert: $cert = New-SelfSignedCertificate -DnsName myweb -Friendlyname MyCert -CertStoreLocation Cert:\LocalMachine\My  $rootStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList Root, LocalMachine  $rootStore.Open("MaxAllowed") $rootStore.Add($cert) $rootStore.Close()  cd iis: new-item -path IIS:\SslBindings\0.0.0.0!443 -value $cert New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https iisreset 
  1. Changes in my docker-compose.override.yml file: added port 443.
   version: '3.4'      services:        testapp.svc:          ports:            - "9091:80"            - "9092:443" 
  1. Changes in my Dockerfile
    FROM microsoft/aspnet:4.7.1     WORKDIR /inetpub/wwwroot     EXPOSE 80      EXPOSE 443     COPY index.html .     COPY certificate.ps1 .     RUN powershell.exe ./certificate.ps1 
like image 191
marvelTracker Avatar answered Sep 23 '22 10:09

marvelTracker