Open In App

How To Add A CA Root Certificate Inside A Docker Image ?

The CA Root Certificate is a digital certificate that is used to only trust software and applications. Using this inside the Docker images establishes trust between the running applications inside the containers and the external host system. It facilitates secure communication by verifying the authentication with SSL/TLS certificates provided by external services. In this article, we will go through in detail and guide how to add a CA root certificate inside a Docker image.

Understanding Of Primary Terminologies

Adding CA Root Certificate Inside A Docker Image: A Step-By-Step Guide

Step 1: Log in to an AWS Account



Step 2: Create An Instance



Step 3: Choosing AMI

Step 4: Choosing Key Pair

Step 5: Configuring Security Groups

Step 6: Launching Instance

Step 7: Connect Instance

Step 8: Navigate EC2 Console

Step 9: Switch To Root User

After landing on the EC2 Console, Run the following command to switch to root user.

sudo su -

Step 10: Install Docker

Now, install the docker software with running the following command:

yum install docker 

and enable the docker service with the following command:

systemctl enable docker --now

Step 11: Create a Directory Structure

mkdir my-docker-project
cd my-docker-project

Within your project directory, create a folder to store your certificate files:

mkdir certs

Step 12: Create the CA Root Certificate

openssl genrsa -out ca.key 4096
openssl req -new -key ca.key -out ca.csr -subj "/CN=MyCA"

openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt
openssl x509 -noout -text -in ca.crt

mv ca.crt  certs/root-ca.pem

Step 13: Write A Dockerfile

Create a Dockerfile in the root of your project directory:

touch Dockerfile
 FROM alpine:latest
# Copy the CA root certificate into the image
COPY certs/root-ca.pem /usr/local/share/ca-certificates/root-ca.crt
# Update CA certificates in the image
RUN update-ca-certificates

Step 14: Build the Docker Image

docker build -t my-docker-image .

Step 15: Verify the Image

docker run --rm -it my-docker-image

Step 16: Usage

CA Root Certificate Inside Docker Image – FAQ’s

Can I update the CA root certificate inside a Docker container?

No. Docker containers are generally comes with immutable nature,.The changes made inside a running container are not perminant. It’s perferred to update the CA root certificate at the time of Docker image build process.

How can I ensure that my application inside a Docker container trusts the added CA root certificate?

On adding the CA root certificate to the Docker image at the time of build process and configuring your application to use the system’s trusted CA store. Your application will automatically trust certificates signed by the added CA.

Is it secure to include a CA root certificate inside a Docker image?

On Including a CA root certificate in a Docker image is mostly safe as long as the certificate is handled securely at the time of build process and that image is itself securely stored and distributed.

Can I remove or revoke a CA root certificate from a Docker image after it has been added?

Once the docker images are build that will act as immutable. So it’s not possible to directly remove or revoke a CA root certificate from a Docker image. Instead, you would need to rebuild the image without including the certificate.


Article Tags :