Pulling from a local docker image instead - image

I have an app with a Dockerfile content that looks like
Dockerfile
FROM SOME_NUMBERS.dkr.ecr.us-east-1.amazonaws.com/app_name:SOME_HEX_VALUE
COPY docker/app/bin/startup.sh /usr/bin/
CMD ["/usr/bin/startup.sh"]
I don't want to pull the image from amazon anymore instead I'd like to "pull" from the already-existing local image pulled the after the first docker-compose up --build command was ran.
When I do docker images I get
SOME_NUMBERS.dkr.ecr.us-east-1.amazonaws.com/app_name SOME_HEX_VALUE SOMESHORT_HEX 2 days ago 1.54 GB which means the image is local already. I understand this
if the host has the image you want docker-compose to use on it it will use that image but if the host doesn't have it, it will go to docker hub or whatever you have setup in your config for registries
So I changed the Dockerfile content to this:
FROM IMAGE_ID:SOME_HEX_VALUE where IMAGE_ID is the image id of the repository I want when I do docker images but then I get Service 'app' failed to build: repository SOMESHORT_HEX not found: does not exist or no pull access and I'd like to know how to tell Docker to use the local image instead of trying to pull from the amazon url. Any ideas?

First pull the images from the remote repository in your local Docker engine:
docker pull SOME_NUMBERS.dkr.ecr.us-east-1.amazonaws.com/app_name:SOME_HEX_VALUE
Now, give the image a new local tag:
docker tag SOME_NUMBERS.dkr.ecr.us-east-1.amazonaws.com/app_name:SOME_HEX_VALUE my-image-name
Now you can simply refer to my-image-name, as in:
FROM my-image-name

You should:
FROM IMAGE_ID
Or, this is already ok:
FROM SOME_NUMBERS.dkr.ecr.us-east-1.amazonaws.com/app_name:SOME_HEX_VALUE
Where SOME_HEX_VALUE is the tag version (the second column in docker images). Note that if the images is present in your computer, docker won't try to pull it again.

Related

Docker on windows generates different image layer id for COPY command

Environment:
Docker on windows
Code in questions: COPY configure_my_app.bat .
Expected: If I run docker build multiple times, I expect the image id to be same from various runs on docker build, given that there is no change in the Dockerfile
What happens: The image id after the above command changes for each run of docker build
I read it somewhere a while ago that this might have something to do with file attributes/permissions. I wonder, how can I get around this ? I want to use layers from cache if Dockerfile is not changed.

How to run local Docker Image

I have an image that I want to run on my local machine. I took this image from my friend and not from docker-hub or any repository. The file shared is in ".img" format.
I am able to import this image on docker but unable to run.
What I did:
Compress the image file from ".img" format to ".tar.gz" format so that the docker image can be imported. I used 7-zip tool to convert this.
From my local I imported the docker image using this new file(.tar.gz)<
Trying to run this imported image but fails.
Commands Executed:
PS C:\Users\C61464> docker import .\Desktop\regchange.tar.gz
sha256:a0008215897dd1a7db205c191edd0892f484d230d8925fd09e79d8878afa2743
PS C:\Users\C61464> docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
<none> <none> 7fdbbdcc59c4 2 minutes ago 1.05GB
PS C:\Users\C61464> docker tag 7fdbbdcc59c4 bwise:version1.0
PS C:\Users\C61464> docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
bwise version1.0 7fdbbdcc59c4 3 minutes ago 1.05GB
PS C:\Users\C61464> docker run -p 8888:80 bwise:version1.0
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: No command specified.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
I searched a lot for this error and found that for running we need to specify the path used while creating the image(In Dockerfile) but I am not sure as I am new to docker. Am I doing something wrong or I need to have the docker file to run this image?
Perhaps the Docker Image you have had no CMD or ENTRYPOINT defined when it was built, so the docker daemon doesn't know what to do with the image
Try doing
docker run -it -p 8888:80 bwise:version1.0 sh
(if it's a *nix based image). That should start an interactive shell.
You can do:
docker run -p 8888:80 bwise:version1.0 {command_you_want_to_run}
On the image when starting it.
The docker image may be broken.
Look inside. See suggestions how to in How to see docker image contents
Run this command to inspect your image
docker inspect [docker-image-name]
Inspect you will see base image and other info about that image

What do these random-looking repository names mean in Docker?

maybe this is a duplicate but I couldn't find any reference for this.
I don't understand what are this images that I see in the output of docker images ls. In the repository column I see some images with a hash in their names.
Thanks!
If you're iterating on a custom image, when you docker build -t imagename ., the imagename:latest tag moves to the newly built image, and the previous image is left behind with just a hash and no other name. You can assign a name to the old image with docker tag, or delete it with docker rmi.
If you are on Docker 1.13 or newer (including any date-format version like 2017.12) then you can ask Docker to clean up the untagged images with
docker image prune
On all Docker versions you can delete the untagged images with the longer
docker images -q -f dangling=true | xargs docker rmi
I found out where the images come from, they are built by Jenkins.

How run docker images without connect to Internet?

I have installed docker in a system which has no connection to Internet so to run an image with docker, I had to download a simple image from this and from another system. Then I put this image in my offline system in this path : C:\Users\Public\Documents\Hyper-V\Virtual hard disks
but when I run docker run hello-world in cmd I see this message:
Unable to find image 'hello-world:latest' locally
and tries to download hello-world image form Internet but it has to no connection to the Internet so it field. Now I want to know where I should put my images in to be visible to docker?
You can do it the easy way without messing around with folders, by exporting the docker image from any other machine with access to internet:
pull the image on a machine with internet access.
$docker pull hello-world
save that image to a .tar file.
$ docker save --output hello-world.tar {your image name or ID}
copy that file to any machine.
load the .tar file to docker.
$docker load --input hello-world.tar
Check out:
https://docs.docker.com/engine/reference/commandline/image_save/
https://docs.docker.com/engine/reference/commandline/load/#examples
You are trying to start a container using the dockerfile. You need to first build the image from dockerfile. You can do this via
docker build -t < image name > < path >
You will require the internet connection while building the image.
You can check the image in your system using
docker images
Once you build the docker image you can start the container without internet connection using
docker run < image name >
Also you can export the same image using docker save and docker load functionalities.
Docker runs in a client-server architecture environment just almost like git. It can pull resources from the server online with the client on "your machine".
The command $docker pull hello-world requires connection to the server as part of docker itself.

I can't find my Docker image after building it

I'm new to Docker, so please allow me to describe the steps that I did. I'm using Docker (not Docker toolbox) on OS X. I built the image from Dockerfile using the following command
sudo docker build -t myImage .
Docker confirmed that building was successful.
Successfully built 7240e.....
However, I can't find the image anywhere. I looked at this question, but the answer is for Docker toolbox, and I don't have a folder /Users/<username>/.docker as suggested by the accepted answer.
You would be able to see your docker images by the below command:
docker images
And to check which all containers are running in docker:
docker ps -a
Local builds (in my case using buildkit) will create and cache the image layers but simply leave them in the cache rather than tell the docker daemon they're an actual image. To do that you need to use the --load flag.
$ docker buildx build -t myImage .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Doesn't show anything, but...
$ docker buildx build -t myImage --load .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myImage latest 538021e3d342 18 minutes ago 190MB
And there it is!
There actually is a warning about this in the output of the build command... but it's above all the build step logs so vanishes off your terminal without easily being seen.
To get list of Images
docker image ls
or
docker images
In addition to the correct responses above that discuss how to access your container or container image, if you want to know how the image is written to disk...
Docker uses a Copy on Write File System (https://en.wikipedia.org/wiki/Copy-on-write) and stores each Docker image as a series of read only layers and stores them in a list. The link below does a good job explaining how the image layers are actually stored on disk.
https://docs.docker.com/storage/storagedriver/
As already said, after the docker images
this command will show you all the images you have locally.
i.e "somth like that"
REPOSITORY TAG IMAGE ID CREATED SIZE
codestandars 1.0 a22daacf6761 8 minutes ago 622MB
bulletinboard 1.0 b73e8e68edc0 2 hours ago 681MB
ubuntu 18.04 cf0f3ca922e0 4 days ago 64.2MB
now you should
docker run -it and the IMAGE ID or the TAG related to the repository you want to run.
Command to list the docker images is :
docker images
The default docker images will show all top level images, their repository and tags, and their size.
An image will be listed more than once if it has multiple repository names or tags.
Click here for the screenshot for more details

Resources