Docker Community Forums

Share and learn in the Docker community.

How do add scripts and files to docker instance

Hi,

I have a docker image to setup netopeer2 for netconf operations.

The final line in my docker file starts the server:

#Will start netopeer2-server with debug.
CMD ["/usr/bin/netopeer2-server", “-d”, “-v2 3”]

Now when everything is setup and running ( a cli) I want to be able, when container is running, to execute some configuration bash scripts when I need a specific configuration.

Currently these scripts are not in container/ not added to docker file but only stored in my repo.

The files are:

ssh_setup.sh
ssh.xml
tls_setup.sh
tls.xml

Both ssh.xml and tls.xml are called from respective setup scripts.

Question 1. Do I need to copy repo version into Docker?

Question 2. How do I execute the scripts?

br,

//mike

Hi Mike,

You have a couple options:

  1. Use your current image as a base image and build a new image, using the COPY command to copy the files into a new image and then use that newly build image to run your container

  2. Or…you could mount a volume
    when you run your container and have the files you need staged in that volume location

In terms of ‘how do you execute the scripts’ - if the container is already running and you just want to execute them after the fact you can exec into the container with a shell and then run the commands ad-hoc. Otherwise, you’re again looking at building your own image and using the RUN instruction to execute the scripts in the image or have those scripts run as part of a wrapper script that is started when the container is spun up.