0

I have created a customised-docker image which runs some code after creating a container.

But I want to attach a config file at the time of deployment and our config file is saved on the local machine.

docker run -d -ti -v /home/logs/:/home/logs/ --name "ContainerName" "ImageName" /bin/bash

I want to attach file at the place of volume.

How can I attach a config file to the container at runtime?

Claudio
  • 10,614
  • 4
  • 31
  • 71
K.D Singh
  • 107
  • 8
  • the volume /home/logs/ on your docker host is mapped to /home/logs/ on the docker container. Modify files in /home/logs/ and it will be visible in the container. you could fetch config files through curl or from etcd, but that depends on how exotic your needs are. – sleepyhead May 06 '19 at 10:55

1 Answers1

2

the docker run options doesnt really let you mess with the image. for that you have the Dockerfile - so you can build an inage of your own, or in this case- kinda like extending the base one:

on your project root directory:

  • copy the logs you need to sit inside your project (so the dockerfile can access them)

  • create a Dockerfile:

    #Dockerfile
    
    FROM <image_name>
    COPY ./logs /home/logs
    
  • build your own image: ( you can also push it to a repo)

    docker build . -t <new_image_name>

  • run the container:

    docker run -d -ti --name "ContainerName" <new_image_name> /bin/bash

Efrat Levitan
  • 5,181
  • 2
  • 19
  • 40
  • Thank you @ for your response, your answer is write but I got my answer by this command: docker run -d -ti -v /home/backup/config/main.json:/home/config/main.json --name "ContainerName" "ImageName" /bin/bash – K.D Singh May 07 '19 at 10:09