V
V
veryoriginalnickname2022-01-11 16:35:22
Docker
veryoriginalnickname, 2022-01-11 16:35:22

How to provide host files to containers?

There are certificates in the folder on the host, they must be transferred to almost all containers. I add volume to docker-compose:

backend:
  container_name: backend
  build: ./backend
  volumes:
   - ./devCerts:/app/certs
  ports:
   - 3333:3333


Next in the dockerfile
ARG CERTSDIR=/app/certs
ARG ROOTCERT=mkcert_root.pem
ARG LINCERT=/usr/local/share/ca-certificates
RUN cp $CERTSDIR/$ROOTCERT $LINCERT/$ROOTCERT
RUN chmod 644 $LINCERT/$ROOTCERT && update-ca-certificates

But gives out
cannot stat '/app/certs/mkcert_root.pem': No such file or directory


Question: how to pass host folder to containers?
Do you really have to add something like
ADD ./../devCerts /app/certs?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mureevms, 2022-01-11
@veryoriginalnickname

You don't quite understand what's going on. First, the backend container is built and only then it is launched with the volumes parameter, which will attach the directory inside the container. Those. you either have to really do ADD in the dockerfile, which is not very convenient. Or specify the attachment directly

volumes:
   - ./devCerts/mkcert_root.pem:/usr/local/share/ca-certificates/mkcert_root.pem

Or just a directory if it is empty inside the container
volumes:
   - ./devCerts:/usr/local/share/ca-certificates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question