2

I'm trying to put some commands in my docker-compose file to be ran in my container and they don't work.

I map a volume from host to container where I have a Root certificate, all I want to do is to run this command update-ca-certificates, so it will updates the directory /etc/ssl/certs with my cert in the container, however it is not happening.

I tried to solve this in a Dockerfile and I can see that the command runs, but it seems that the cert is not present there and just appears after I login to the container.

What I end doing is to get into the container, then I run the needed commands manually.

This is the piece of my docker-compose file that I have been trying to use:

build:
      context: .
      dockerfile: Dockerfile
    command: >
      sh -c "ls -la /usr/local/share/ca-certificates &&
             update-ca-certificates"
    security_opt:
      - seccomp:unconfined
    volumes:
      - "c:/certs_for_docker:/usr/local/share/ca-certificates"

In the same way I cannot run apt update or anything like this, but after connecting to the container with docker exec -it test_alerting_comp /bin/bash I can pull anything from any repo.

My goal is to execute any needed command on building time, so when I login to the container I have already the packages I will use and the Root cert updated, thanks.

2
  • 1
    Can you post you Dockerfile ? Commented Jun 7, 2019 at 8:43
  • @MarcABOUCHACRA I was just missing the env vars in the Dockerfile, thanks for trying to help. Commented Jun 18, 2019 at 8:31

1 Answer 1

0

Why dont you do package update/install and copy certificates in the Dockerfile?

Dockerfile

...
RUN apt-get update && apt-get -y install whatever

COPY ./local/certificates /usr/local/share/my-certificates

RUN your-command-for-certificates

docker-compose.yml

version: "3.7"
services:
  your-service:
    build: ./dir
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Your answer help me to understand what I did wrong... The thing is that I thought that using the environment variables only in the docker-compose file was enough to have the container ready to use the linux repo, and it is not like that. What I did was to use a Dockerfile with the enviroment variables, then I put the needed Linux commands as you advised and Voila!! evertything is working. Thank you :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.