Run a script inside docker container

Is there a way to run a script from Octopus inside a container? For CI purposes we intend to create an image from a build and then at deploy time run config transformation on a container based on that image. This seems to be the logical series of events when using docker and yet there doesn’t seem to be a native way to transform files inside a container (at least no way to use wildcard and filetype search). That being said, we have found that the easiest way to do the transformations is by running a powershell script inside the container. From a very basic test though, it doesn’t seem that octopus allows you to run ‘docker exec powershell’ and then continue running inside the container. Is there a way to achieve this ?

Thanks,
Adam

We have a similar issue. We were able to get the docker container to run the appropriate command by putting the command in the “Command” field under “Additional Arguments”.

However, our issue is that we aren’t seeing any of the output of that command in the Octopus console, so we have no idea what happened we the docker container ran.

By design we decided to avoid performing any modification of a container before running it as that can sometimes be seen as an anti-pattern in the container community. We would recommend using environment variables to pass in values needed by the container internals. Check out this post by Dan Tehranian about some options with getting application configuration into your docker container.

As @MikePennington mentioned you can use the Command field of the step, however by design we treat the docker run invocation as fire and forget, since if you are deploying a container we don’t want to block the deployment for as long as your application is running. If you want to inspect what happened in the container from this command, we would reccomend adding an additional script step and using the docker logs command to pull out the result. We cover this kind of command in the “Docker run with networking” walkthough in our docs.

Performing configuration transforms are a little more tricky since by definition you are trying to modify the container before running it. One idea might be to change the entrypoint of your Dockerfile to run a script that first takes an environment variable, performs the transform manually via the command line using something like WebConfigTransformRunne before starting up your application.

Let me know if these suggestions help get your deployments running.
Cheers,
Rob