How can i create docker image from my test.1.0.0.nupkg?

Hi Octopus Team,

I wanted to create a docker image from test.1.0.0.nupkg and push it into dockerhub and launch a container out of the image.

i am following the external documentation on similar thing:

from that document, To create the Octopus image we need to use a pivot machine with Docker for Windows installed.
my question is that: what is pivot machine in this scenario? and what is Application Location?

could you please help me with this one?

Thanks,
Sudheer.

Hi Sudheer,

We didn’t write that post. But I believe when the author says “pivot machine” they simply mean you need a machine with docker installed to be able to perform the docker build and push commands and to extract the files from the package.
So in that context, the pivot machine is simply a Windows server with Tentacle installed.

The Application Location is the directory which the first Deploy a Package step extracted the NuGet package. It is used as the Path parameter to docker build. You can access this using the Octopus.Action[Unpack Docker WebApp].Output.Package.InstallationDirectoryPath variable.

If you want to see exactly what the Docker - Create and Push Image community step is doing, you can view the script source in our community library.

That community step will currently only push to Docker Hub. If this is fine for you, then following that post is great.

However, it seems that the post was written nearly two years ago, and a few things have changed since then which provide some alternative ways to achieve your goal of building and pushing a docker image.

In 2018.8 we made some enhancements to script steps which mean you can now reference the NuGet package from a script step, and run the docker build and push commands from the same step (rather than having two steps). We also introduced Worker Pools, which provides a potentially nicer way to run this step on any machine in the pool, rather than need to configure a deployment target in each environment. Alternatively, if you are using an on-premise Octopus Deploy instance, then you could install docker on the Octopus Server and execute the script step on the server.

So it would become something like this:

  1. Push your NuGet package to Octopus from your build server
  2. Add a Run a Script step to your deployment process. This step should be configured to run wherever you installed docker. This can be the Octopus server, a worker, or a deployment target.
    2a. Add a package reference to your NuGet package. Configure it to be extracted.
    2b. For the body of the script step, you can use the source of the community library step as a guide. It may also be worth reading our recent post on running docker compose. Although the step in that post is composing two docker images, rather than building one, it covers some similar territory.

While writing your own step may be a little more work, it will give you more flexibility (if you need it), and a possibly slightly neater solution.

For our curiosity, why are you trying to build the container image in Octopus? Do you intend to build an image per environment (or per tenant)? Or do you simply see it more as part of the deployment process rather than the build process?

I hope that helps! If not, or if we can be of any further help, just let us know.

Regards,
Michael Richardson

Hi Michael,

i created the Pivot machine (Linux installed docker in it) and able to push .nupkg to pivot machine and trying to build the docker image and publish to docker hub but when i run from octopus, it’s failing. If i run manually from my pivot machine, it able to succeed.

**error from octopus: - **
/home/ec2-user/.octopus/Applications/OctopusServer/Feature\ Environment\ 5/Feature/aspnetapp/2.0.0

October 19th 2018 17:28:25

Info

sudheeramgothu/test

October 19th 2018 17:28:25

Info

sudheeramgothu

October 19th 2018 17:28:25

Info

Building the Docker Image

October 19th 2018 17:28:25

Error

/home/ec2-user/.octopus/OctopusServer/Work/20181019212822-201934-314/Script.sh: line 26: sudo docker build -t sudheeramgothu/test /home/ec2-user/.octopus/Applications/OctopusServer/Feature\ Environment\ 5/Feature/aspnetapp/2.0.0: No such file or directory

October 19th 2018 17:28:25

Fatal

The remote script failed with exit code 127

October 19th 2018 17:28:25

Fatal

The action Docker - Create and Push Image Copy on sudheer’s linux Machine failed

success message from pivot machine manual:
[ec2-user@ip-172-12-0-227 ~]$ sudo docker build -t sudheeramgothu/test /home/e-user/.octopus/Applications/OctopusServer/Feature\ Environment\ 5/Feature/aspnetapp/2.0.0

it able to create the docker image.

this is my application location: /home/ec2-user/.octopus/Applications/OctopusServer/Feature\ Environment\ 5/Feature/aspnetapp/2.0.0

and this is my Bash script:

Get the parameters.

appLocation=$(get_octopusvariable “ApplicationLocation”)
dockerFile=$(get_octopusvariable “DockerFile”)
imageName=$(get_octopusvariable “ImageName”)
tag=$(get_octopusvariable “ImageTag”)
dockerUsername=$(get_octopusvariable “DockerUsername”)
dockerPassword=$(get_octopusvariable “DockerPassword”)

echo “$appLocation”
echo “$imageName”
echo “$dockerUsername”

Prepare the final image name with the tag.

#$imageName += ‘:’ + $tag

Create the docker image

echo “Building the Docker Image”

	"sudo docker build -t $imageName $appLocation"
    #echo "Pushing docker image to hub tagged as $imageName"
    #sudo docker login -u $dockerUsername -p $dockerPassword
	#sudo docker push $imageName

Could you please help me ?

Thanks,
Sudheer.