running incorrect docker image osx - docker

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.

Related

How can I update Docker image after changing few lines of code in my app?

Dockerfile I just built a Docker image using the below command in my app working directory:
docker build -t imagename:latest .
The Docker image is successfully built after a few minutes and the application is running as well once I used the below command:
docker run -p portnumber:portnumber imagename:latest
But now I want to update 2 lines of code in my application codebase. Suppose I added the code and wants to see if my application is working or not so how could I do that? Do I need to follow the below steps?
1. Delete the Docker image
2. Rebuild the image using the above command
3. See if the app is working or not using the "docker run" command?
I want to know that how can I update my Docker image? My Dockerfile is the same and there won't be any changes. I don't want to rebuild the whole Docker image again because initially, the size of all packages were around 2GB. Can anyone help me that what should I do next? Thanks in advance.
OS: Ubuntu
Application framework: Streamlit
Although you asked specifically how to update (rebuild) your docker image, it is my guess that you are in fact in need of a different solution.
If you are developing on a dockerized version of your application (which is good), it is impractical to rebuild the image with every change you do in your code.
A better, and more common approach, is to mount your local folder into the container, so the running container and your local machine actually share a folder.
This way you can just edit your code, and it is reflected in the container immediately.
So, your docker run command might look something like this:
$ docker run -v $PWD:/path/to/app/in/container -p PORT:PORT IMAGE_NAME
Read more about docker volumes.
Read more about docker for development environments.
Read about using docker-compose for development.
Rebuilding your docker image might not be as much as a hassle as you think !
When you build an image, each line with the command RUN, COPY or ADD of your Dockerfile is made into a layer of your image. When you rebuild the image, only the updated lines of the Dockerfile should rebuild. If you do not delete the old image so that it's in cache, that is.
If you try it, you should see only one or so layers of your image updating (and those below it)
An alternative would be to not put your code into your build and to insert it in the container with a volume at runtime. Depending on your use, it could be something. But it is a quite different use case and might not apply.

what is the correct way to update a docker image

I created an ubuntu docker container, copied a mirror of a c++ library (sized 1.2 gb) I'll be using on it (on the docker container's home directory), built it on it and forgot to remove the mirror before creating the image and pushing to docker hub.
I then tried to re-run the container from the image to remove the c++ mirror so i can commit the new image , but the new image didn't downsize for a reason i ignore . After i run docker images i still have :
REPOSITORY TAG IMAGE ID CREATED SIZE
tawfik741/opencascade-build amd64 74f333aa7293 16 minutes ago 1.79GB
The commands i ran are :
Creating the container with :
docker run --name opencascade-build -it ubuntu:latest bash
Copying the C++ library mirror so i build it on the container :
docker cp opencascade-dev-mirror [my-container-id]:/home
After building my library i did :
sudo docker commit --author "Tawfik" --message "opencascade-build" [my-container-id] tawfik741/opencascade-build:amd64
and pushed it to a private repo with :
docker push tawfik741/opencascade-build:amd64
after figuring up that i forgot to remove that opencascade-dev-mirror from the container i decided to run the container , remove it , and save the new image , i tried in to save a new image but it's exactly the same size as the old one :
I ran the docker container from the image with :
docker run -it tawfik741/opencascade-build:amd64 /bin/bash
I updated the container then ran :
docker commit --author "Onboard SARL" --message "opencascade-build" [my-container's id] tawfik741/opencascade-build:correction-amd64-correction
but the tawfik741/opencascade-build:amd64-correction has the same size as the tawfik741/opencascade-build:amd64 image .
You cannot edit, modify, or update an image once you've created it.
You can create a new image based on an existing image. The way Docker works internally, the new image always contains the entire old image, plus a description of what changed from the old image. Doing this never makes the new image smaller, only larger.
You need to start over and create a new image starting from the original base image. If you use the standard docker build command and Dockerfile system, it should be enough to delete the COPY line that adds the large file to the image and rebuild. If you're using docker commit, you need to completely start over and hope you repeat the same manual commands in the same way; even if you're trying to "iterate rapidly" you'll be much better off switching to a Dockerfile.

Docker :: How to see the packaging inside an image made from Docker for Mac?

I created an image wildfly using Docker Desktop for Mac. Then I tried to run it, however, there seems to be some deployment error when the image is run.
In order to check if the docker file packaged the image properly or not, I would like to debug it by checking its content.
Is there a way to see the contents inside an image made from Docker Desktop for Mac?
docker history shows the commands used to build the image, otherwise, you could docker run the image, using sh as the command to enter into a terminal. Then you can browse the file system as normal
Rather than looking at the image, it would probably be easier to start the image from a shell and introspect it via that.
docker run -it wildfily /bin/sh

Updating a docker image without the original Dockerfile

I am working on Flask app running on ec2 server inside a docker image.
The old dev seems to have removed the original Dockerfile, and I can't seem to find any instructions on a way to push my changes into to the docker image with out the original.
I can copy my changes manually using:
docker cp newChanges.py doc:/root/doc/server_python/
but I can't seem to find a way to restart flask. I know this is not the ideal solution but it's the only idea I have.
There is one way to add newChanges.py to existing image and commit that image with a new tag so you will have a fall back option if you face any issue.
Suppose you run alpine official image and you don't have DockerFile
Everytime you restart the image you will not have your newChanges.py
docker run --rm -name alpine alpine
Use ls inside the image to see a list of existing files that are created in Dockerfile.
docker cp newChanges.py alpine:/
Run ls and verify your file was copied over
Next Step
To commit these changes to your running container do the following:
Docker ps
Get the container ID and run:
docker commit 4efdd58eea8a updated_alpine_image
Now run your alpine image and you will the see the updated changes as suppose
docker run -it updated_alpine_image
This is what you will see in your update_alpine_image with having DockerFile
This is how you can rebuild the image from existing image. You can also try #uncletall answer as well.
If you just want to restart after docker cp, you can just docker stop $your_container, then docker start $your_container.
If you want to update newChanges.py to docker image without original Dockerfile, you can use docker export -o $your_tar_name.tar $your_container, then docker import $your_tar_name.tar $your_new_image:tag. Later, always reserve the tar to backup server for future use.
If you want continue to develop later use a Dockerfile in the future for further changes:
you can use docker commit to generate a new image, and use docker push to push it to dockerhub with the name something like my_docker_id/my_image_name:v1.0
Your new Dockerfile:
FROM my_docker_id/my_image_name:v1.0
# your new thing here
ADD another_new_change.py /root/
# others
You can try to examine the history of the image, from there you can probably re-create the Dockerfile. Try using docker history --no-trunc image-name
See this answer for more details

Docker build command with --tag unable to tag images

I have trying to build a Docker image using a Dockerfile available locally.
docker build -t newimage .
I have used this command multiple times earlier too, but somehow its not working currently and i am stuck finding the reason for it.
I will be really helpful if someone can help me with a possible solution or a possible area to look for an issue.
i already had a look over other posts that could have been related for example :
Docker build tag repository name
Okay! I found out the reason for issue.
DOCKER BUILD PROCESS
When we build a docker image, while creating a image several other intermediate images are generated in the process. We never see them in docker images because with the generation of next intermediate image the earlier image is removed.And in the end we have only one which is the final image.
The tag we provide using -t or --tag is for the final build, and obviously no intermediate container is tagged with the same.
ISSUE EXPLANATION
When we try to build a docker image with Dockerfile sometimes the process is not successfully completed with a similar message like Successfully built image with IMAGEID
So it is so obvious that the build which has failed will not be listed in docker images
Now, the image with tag <none> is some other image (intermediate). This creates a confusion that the image exists but without a tag, but the image is actually not what the final build should be, hence not tagged.
If your Dockerfile's last line is RUN then it may hang on that during build.
I changed RUN npm start to CMD ["npm", "start"] and it's tagging now.
There's nothing wrong with Docker.
An image can have multiple tags:
alpine 3.4 4e38e38c8ce0 6 weeks ago 4.799 MB
alpine latest 4e38e38c8ce0 6 weeks ago 4.799 MB
In this example the image with id 4e38e38c8ce0 is tagged alpine:latest and alpine:3.4. If you were to execute docker build -t alpine . the latest tag would be removed from the image 4e38e38c8ce0 and assigned to the newly built image (which has a different id).
If you remove the last tag from an image, the image isn't deleted automatically. It shows up as <none>.
Docker also uses a cache. So if you build an image with a Dockerfile, change that file, built the image again and than undo the change and build again you will have two images - the image you built in the first and last step are the same. The second image will be "tagged" <none>.
If you want to keep multiple version of an image use docker build -ttag:versionimage:tag . where versiontag is changed every time you make some changes.
Edit:
What I called tag is actually the image name and what I called version is called the tag: https://docs.docker.com/engine/reference/commandline/tag/
One of walkaround solution for this case, run below command immediately after build command, if all other images has already been taged.
docker tag $(docker image ls | grep "<none>" | awk '{print $3}') newimage:latest
As I know this will work only in linux os.

Resources