I've been trying to use docker for a while, these are docker images I've downloaded.
debian latest 8c00acfb0175 2 weeks ago 125.2 MB
sameersbn/postgresql latest 1da0f78d061e 3 weeks ago 231.6 MB
ubuntu latest 91e54dfb1179 5 weeks ago 188.4 MB
docker/whalesay latest fb434121fc77 4 months ago 247 MB
sameersbn/postgresql 9.4 271ad7e099d3 7 months ago 228.2 MB
How can I've base image for debian or ubuntu locally, and build some testing images on top of them and not disturb base images, so that I don't have to download base docker images again, and I can use fresh downloaded images multiple time ?
In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.
You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.
It is that much easy to copy Docker images from one host to another without using a repository. To export the alpine image to a tar file, run the docker save -o <tar file path in source host machine> <image_name> command, specifying a name for the . tar file, and the docker image.
Simply write a Dockerfile starting with:
FROM debian:latest
...
(using the FROM
directive)
That will create a local image based on debian, and since debian is already downloaded, it won't be downloaded again.
Note: it is best to avoid the "latest" tag: see "Docker: The latest Confusion" by Stack Overflow contributor Adrian Mouat.
Using actual labels is more precise:
docker pull debian:7.8 docker pull debian:wheezy
If wanted to do something in ubuntu is there a way when: I just execute command
docker copy "image_name"
and then do whatever I want to (run image, clone some git repo, install some packages, test it) , and then just delete itdocker rmi "image_name"
(when I'm done with image) .
Yes: you can docker run --it <image> bash
(fomr images which includes bash
), and exit that bash: your container will be exited: you can then docker commit <containerrid> newimage
, and you will get a copy of the original image.
The images what you listed using the command "docker images" can be re-used. Here are 2 ways how you can extend or re-use an base image without downloading it again.
In Dockerfile you can put the Instruction "FROM REPOSITORY_NAME:TAG_NAME" as first line to re-use already downloaded base image
FROM REPOSITORY_NAME:TAG_NAME
In "docker images" command output, 1st column gives REPOSITORY name and 2nd column give TAG name.
You can further add more instructions in Dockerfile and build it.
a. Start the container from the base image
b. Login to the container, make the changes to the container like install additional rpms etc if required.
c. commit the results for new image created on base image.
docker commit -m "installed wireshark" -a "admin" "container-id" "your_repository_name"/"user_name":"New_TAG"
d. Run "docker images" command, you can see the new image (which is prepared on top of existing, already downloaded image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With