Friday, 21 April 2017

docker, make your base docker image, II


You base image will have different versions sooner or later, e.g. you may using node 0.20.xx for now, then you build your image for this version , then Node may update soon and it may become 0.30.xx, then you will create a new image for this new node.

if you want to know more about it in detail please read below, otherwise if you want to know how to do and get the command, please jump below part and go to solution section directly.


Most docker images use tag(something like version) to do this. e.g. if you want to get an image of java 8, then you do :

docker pull java:8

if you need java7, then you do :

docker pull java:7

the version number in above comands are tags of an image, then there is a new concept you need to know is docker image repo. java is a repo above, 8 is a tag of a image in this repo, so when you pull java:8 your docker client actually request docker hub to got to java repo to search an image which has "8" tag.

Note, above version numbers are not version numbers, they are version codes, which means it could be a string. like "beta.10.100.s"

So tag is version, version is tag in docker.

Then how to add tags into image on my docker hub repos?

answer is  : you need to tag then locally, you can:

Solutions:

give tags to an image when you are building it:

docker build -f your.dockerfile -t you/repo:latest -t you/repo:yourVersionCodeHere .

or give tags after an image is built by:

docker tag you/repo:yourCurrentVersionCode you/repo:newTag



After that, you can push them,

then you just need run :

git push you/repo

it will push all versions/tags to your docker hub repo.




Later if you update node from 0.20.xx to 0.30.xx then you need to tag the new build with "latest".

Then  when you run :

docker run your/repo

it will use the new image,  you can try below command to check:

docker run your/repo node -v

it will show node version in the image.




No comments:

Post a comment