26

Let's say one of the official docker base images ubuntu:latest and I have a dockerhub account myaccount. How to clone ubuntu:latest to myaccount's repository? The work flow can then be introduced as follows,

$ docker pull myaccount/ubuntu:latest
$ docker run -it myaccount/ubuntu:latest /bin/bash
# root@mycontainer: apt-get install onepackage
# root@mycontainer: exit
$ docker commit mycontainer myaccount/ubuntu:latest-new
$ docker push myaccount/ubuntu:latest-new

I need push just the delta latest-new minus latest.

sof
  • 9,113
  • 16
  • 57
  • 83
  • You should not make changes manually by going in container and then making changes and committing the image. This doesn't preserver the metadata changes. And your history won't show the changes. So always use a Dockefile to make changes on top of another image that you want to customize. Rest your main question is answered by @Andy – Tarun Lalwani Jul 28 '17 at 04:14

2 Answers2

25

Use docker tag ubuntu:latest myaccount/ubuntu:latest. (you should also tag with a specific version number so that you can still reference the image when you update :latest)

Then docker push myaccount/ubuntu.

It won't actually make a copy, but it will add the new tag to the existing image. Other people won't see the tag unless they docker pull myaccount/ubuntu.

Andy
  • 35,844
  • 6
  • 43
  • 50
  • 1
    What I expect is that dockerhub can provide us with the analogical function of github `fork`. – sof Aug 15 '14 at 09:48
  • Although what dockerhub does is more verbose that githhub `fork`, it satisfies `delta push`. Accepted. – sof Aug 15 '14 at 10:10
  • Oh, it's just a tagged link. Will the target repository on dockerhub become broken if the linked source is removed by chance? – sof Aug 15 '14 at 10:30
  • 3
    Empirically testing, it looks like deleting the source repository does not affect the image in the "aliased" repository. I believe this is because both are actually aliases and neither is considered the canonical source. The persistence of referent image in the Docker Registry seems independent of the tagged names/aliases. At least that's the current behavior. – Andy Aug 15 '14 at 17:49
  • This doesn't answer the complete question, which includes adding a package to the cloned image. I have the same question, and nothing in this SO directly explains how to do that. It seems this writeup gives two methods for achieving the modification aspect: https://linuxhandbook.com/modifying-docker-image/ – Peter H. Boling Oct 02 '21 at 02:26
18

Macos Use the command

$    docker pull NAME:tag
$    docker tag NAME:tag myaccount/name:tag
$    docker login
#    yourname
#    password
$    docker push myaccount/name:tag
Be Live
  • 191
  • 1
  • 3