Build and publish your own Image with Docker and Artifactory






The true power of docker, having the ability to pack and ship your application, so others could run unlimited amount of containers based on our Image that contains our application code.
In this post we are going to build our own docker image from scratch, and publish it to a remote repository.

Define the flow

A standard flow of packaging and shipping our app would look something like this:

1. Create a Dockerfile which will contain our set of layers and "instructions" for designing our image.

2. Build the image which will serve as a "Master template" for our application containers.

3. Publish our build to a repository so others could pull and run containers from our Image. 
(In our example we are going to uje JFrog Artifactory.)


Let's get to work...

1. Create a Dockerfile.

A Dokcerfile is basically a text file that contains a set of commands which will assemble our Image. (An Image is much like a base template).

For this example, we will build a simple "Hello world" image with a basic command line output.

I will start by creating a work directory to host my Dockerfile. (I will call it workdir)








So, as we see in the above example:

  • We will start from a base layer of the latest alpine image.
  • Next up is just metadata listing me as the maintainer. 
  • Next, we are using the CMD instruction to execute a shell command to $ echo hello-world.

Thats it. As simple as that.


2. Build our Docker Image.

Now, we are going to build our Docker Image. 
For that, we are going to navigate to our workdir from the terminal and run the build command.

In order to make the next steps of deployment easier we are going to tag our docker Image in the following convention:




So, my command is going to look something like this:




Want to test it out and see if it works?





And it works fine... 

That's it. My Image is built and ready to be shipped.

3. Publish our build 

Now, I'm going to publish our freshly created Image to Artifactory. If you think about it, we are fulfilling Docker's vision. Build, Ship and Run. 

We are about to ship our image to our company's central repository so anyone could download and run a container from it. 

    a. Setting up a local docker repository in our Artifactory instance


First of all I'm going to set up a local docker repository on my Artifactory instance. I'm going to call it 
docker-local to match my Image tag. (Remember? - step number 2.)




Optionally, when setting up the repository, you can choose to index it in Xray to later on scan your deployed packages and  find violations and vulnerabilities according to pre-defined company policies.



Now, I have a repository ready to host our Docker image.



    b. Pushing our Image to the docker-local repository

The first step is to configure our reverse proxy connection. 
That can be achieved via configuring our docker /config.json file or simple login in to Artifactory from the terminal.


It will require a user and password and then output whether the connection was successful or not.

Now, we are ready to push our Image.



That's it. We did it.




We can go to the platform's UI and see that our repository is now populated with the image we created.





I hope you have enjoyed this post, see you in the next one.




Comments

  1. Best 7 Casinos in Seattle - MapYRO
    Find your nearest 경산 출장샵 casino 의정부 출장안마 in Seattle in 2021. Wherever you 양주 출장마사지 want to find casino games, slots 과천 출장마사지 and 삼척 출장마사지 table games, you've got to

    ReplyDelete

Post a Comment

Popular posts from this blog

Chromedriver - Under The Hood

Sharing is caring - Intro to Jenkins shared libraries

Build Your Own Custom AMI With Packer