Docker image exists, but "docker run" doesn't find it - docker

Here is the link of docker hub from where I am pulling the image "https://hub.docker.com/r/zcgzcgzcg/squadv2/tags"
My main motive is to run the environment on my machine locally.

If you do not specify which version of zcgzcgzcg/squadv2 you want, Docker will, per default use the tag latest.
But you don't have any image zcgzcgzcg/squadv2:latest.
You have one tagged 4.0, though, so:
docker run zcgzcgzcg/squadv2:4.0
Is what you are looking for.
This is implicitly described in the documentation where they point at the fact that:
$ docker run --name test -it debian
This example runs a container named test using the debian:latest image.
Source: https://docs.docker.com/engine/reference/commandline/run/#assign-name-and-allocate-pseudo-tty---name--it
But it is also explicitly descriped in the docker pull page:
If no tag is provided, Docker Engine uses the :latest tag as a default.
Source: https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-from-docker-hub

The problem is you are not specifying the tag in your docker run command. You have pulled 4.0, as you can see in the docker images output - but when you don't specify the tag, it will default to latest - which you don't have. So, try this:
docker run zcgzcgzcg/squadv2:4.0

Related

Check if local docker image latest

In my use case I always fetch the image tagged with "latest" tag. This "latest" tag gets updated regularly. So even if the latest tag image is updated on registry, the "docker run" command does not update it on local host. This is expected behavior as the "latest" image exists on local host.
But I want to make sure that if the "latest" image on local host and registry are different then it should pull the latest image from registry.
Is there any way to achieve this?
You can manually docker pull the image before you run it. This is fairly inexpensive, especially if the image hasn't changed. You can do it while the old container is still running to minimize downtime.
docker pull the-image
docker stop the-container
docker rm the-container
docker run -d ... --name the-container the-image
In an automated environment you might consider avoiding the latest tag and other similar fixed strings due to exactly this ambiguity. In Kubernetes, for example, the default behavior is to reuse a local image that has some name, which can result in different nodes running different latest images. If you label your images with a date stamp or source-control ID or something else such that every image has a unique tag, you can just use that tag.
Finding the tag value can be problematic outside the context of a continuous-deployment system; Docker doesn't have any built-in way to find the most recent tag for an image.
# docker pull the-image:20220704 # optional
docker stop the-container
docker rm the-container
docker run -d ... --name the-container the-image:20220704
docker rmi the-image:20220630
One notable advantage of this last approach is that it's very easy to go back to an earlier build if today's build happens to be broken; just switch the image tag back a build or two.

Commands are not working in Ubuntu container

I have created a container using the following command: docker container run -i ubuntu. However, when I try to run a command within the container, such as cd, I get the following error: bash: line 1: cd: $'bin\r': No such file or directory. What could be the issue?
When you docker run an image, or use an image in a Dockerfile FROM line, or name an image: in a Docker Compose setup, Docker first checks to see if you have that image locally. If you have that image, Docker just uses it without checking Docker Hub or the other upstream registry.
Meanwhile, you can docker build or docker tag an image with any name you want...even a name that matches an official Docker Hub image.
You mention in a comment that you at some point did run docker build -t ubuntu .... That replaces the ubuntu image with what you built, so when you later docker run ubuntu, it's running your modified image and not the official Docker Hub Ubuntu image.
This is straightforward to fix. If you
docker rmi ubuntu
it will delete your local (modified) copy, and the next time you use it, Docker will automatically pull it from Docker Hub. It should also work to
# Explicitly get the Docker Hub copy of the image
docker pull ubuntu
# Build a custom image, pulling whatever's in the FROM line
docker build --pull -t my/image .
(You can also hit this in a Docker Compose setup if you specify both image: and build:; this instructs Compose on an explicit name to use for the built image. You do not need to repeat the FROM line in image:, and it causes trouble if you do. The resolution is the same as described above. I might leave image: out entirely unless you're planning to push the image to a registry.)

Publishing Container to Quay by Example

I'm trying to figure out how to publish a versioned Docker container to Quay.io and am not seeing how to do so in their docs. From the docs:
# Login to Quay.io
docker login quay.io (will now be prompted for username + password)
# Get your <containerID>
docker ps -l
# Tag that container by <containerId>
docker commit <containerId> quay.io/<myUsername>/<myRegistry>
# Now publish it to Quay.io
docker push quay.io/<myUsername>/<myRegistry>
However this leaves me very confused:
What if I want my containers tagged/versioned with, say, 1.0.0-SNAPSHOT, or 1.0-rc, or 2.0 or 3.1.6-G.A? Where do I specify the actual tag name/version?
When I run the docker push command, how does Docker know which (tagged/versioned) container to publish?
First, it's worth noting that you don't push containers to a registry. You push images. The docker commit command in your question creates new image based on an active container.
When assigning tags to images -- using either the docker tag command, which is more common [1], or when using docker commit -- the format of a tag is [<registry>/]<repository>[:<tag>], where [...] is used to represent an option component. So for example you might tag an image targeting your account on Docker Hub like this:
docker tag smeeb/webserver
This would be assigned the latest tag, since you haven't specified one explicitly. To explicitly assign the tag awesome instead of latest:
docker tag smeeb/webserver:awesome
When you're tagging an image for an alternate registry, you include the registry name as part of the tag, as in:
docker tag <imageId> quay.io/smeeb/webserver
Here, quay.io is the registry, smeeb/webserver is the repository, and you've implicitly assigned the latest tag. You can be explicit instead:
docker tag <imageId> quay.io/smeeb/webserver:1.0.0-SNAPSHOT
And so forth. You can use the same syntax when creating images with docker commit.
[1]: The reason I saw that using docker tag is more common is that use of docker commit is generally considered an anti-pattern. Use a Dockerfile to create your new image, which makes it much easier to reproduce the same configuration (and allows you to version control the configuration of your image).

Docker --tag vs --name clarification

I'm pretty new to docker and I'm a bit puzzled by the difference between tagging (--tag) an image and assigning it a name (--name).
For example, I can see that if I build my custom image out of a Docker file, I can tag it with a name:
sudo docker build --tag=tomcat-admin .
sudo docker run -it tomcat-admin
Passing the name to docker inspect produces a result:
docker inspect tomcat-admin
However it doesn't contain the same attributes of a "named" image:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' tomcat-admin
Template parsing error: template: :1:19: executing "" at <.NetworkSettings.IPA...>: map has no entry for key "NetworkSettings
"
Somebody to shed some light on it?
Thanks!
I think you mixed two concepts here, which causes the confusion. On the one hand there is a Docker image which you can think of as a blueprint for starting a container. On the other hand there are containers which are running instances that are based on an image.
When you docker build -t tagname . you are creating an image and tag it with a "name:tag" format usually. So for example, you are building your image as
docker build -t myimage:1.0 .
which creates a new image that is named myimage with a version of 1.0. This is what you will see when you run docker images.
The --name parameter is then used when you create and start a new container based of your image. So for example, you run a new container using the following command:
docker run -it --name mycontainerinstance myimage
This creates a new container based of your image myimage. This container instance is named mycontainerinstance. You can see this when you run docker ps -a which will list the container with its container name mycontainerinstance.
So to better understand the difference, have a look at the docs for building an image and running a container, specifying an image. When reading the docs you will notice which commands target an image and which commands are for containers. You will also see, that there are commands that work for images and containers like docker inspect does.
Inspecting for a network address of course only works when you provide a container name, not an image. In your special case, the container got a generated name, which you can see by running docker ps -a. When you provide this name to the docker inspect command, you will likely see the ip address you wanted.
You tag an image
docker build --tag=tomcat-admin .
but you assign a name to a container
docker run -it tomcat-admin
You can assign multiple tags to images, e.g.
docker build --tag=tomcat-admin --tag=tomcat-admin:1.0 .
If you list images you get one line per tag, but they are related to the same image id:
docker images |grep tomcat
tomcat-admin 1.0 955395353827 11 minutes ago 188 MB
tomcat-admin latest 955395353827 11 minutes ago 188 MB
You can tag images also a second time, not just when you build them, so you can keep different image versions.
When you run a container based on a specific image, you can assign it a name, so you can refer it using the name instead than using the containerId.
Obviously you get different attributes by inspecting images and containers. I think it's more clear if you use different name for image tag and container name, e.g.
docker build --tag=tomcat-admin .
docker run -d -ti --name=tomcat-admin-container tomcat-admin
docker inspect tomcat-admin ==> You inspect the image
docker inspect tomcat-admin-container ==> You inspect the container
The confusing thing is that a tag consists of a name and a tag. In documentation you can see that:
--tag , -t Name and optionally a tag in the ‘name:tag’ format
So if you omit the :tag part, you actually add a name for the image. That's it.
The difference between image names and container names is explained in other's answers.

running incorrect docker image osx

I created a new image running:
docker build -t team1/es-image2 . | tee build.log
First, the create date doesn't reflect today's date. I wasn't concerned with that at first but after running it, it sort of makes sense...the running image is from another image created previously. I ran it with this command:
docker run -i -t --rm -P team1/es-image2
I verified that the correct image was running using:
docker ps
I deleted the older image and tried running again but it still appears to be running the older image because -P showed all the older mapped ports and the working directory was also from the older image.
So, I can't understand why, the build is using the older containers even though the Dockerfile is not specifying all the items that were specified in the older image.
Thanks!
docker ps
is only to show container.
To show images you need to use
docker images
And to delete them use
docker rmi
A little clarification about image and container.
An image is the definition of a container, and a container is a part of the system isolated from the current directory tree.
You use an image to run a container. You can use the same image to run multiple container.
When building the image from the Dockerfile, you may specify --no-cache=true to exclude any intermediate builds.

Resources