Push docker image to docker hub
1. Pull the Ubuntu image
First you should be pulled docker image from docker hub registry.
After that you can list all the docker images like this.
docker images
You can filter
docker images by using grep
docker images | grep <DOCKER IMAGE NAME>
2. Run Ubuntu docker image
After you can run that Ubuntu docker container like this.
docker run -it -d <DOCKER IMAGE NAME/ID>:<DOCKER IMAGE VERSION>
That running Ubuntu docker container is working like Ubuntu virtual machine.
After that we can list all the running containers.
docker ps
Moreover we can list all the stopped containers.
docker ps -a
3. Execute docker container
Earlier I mentioned that running Ubuntu docker container is working like Ubuntu virtual machine. So you can log into that Ubuntu container.
docker exec -it <DOCKER CONTAINER ID>
After that process you can do any thing inside it.
Here we listed all the files by using “ls” command. “ls” is Linux command. You can use any Linux commands inside this Ubuntu container.
We created new directory inside that Ubuntu container by using “mkdir” command.
4. Commit changes
We did few changes inside that Ubuntu container. So we must save all the changes.
docker commit <DOCKER ID> <PUBLIC REPOSITORY NAME>/<NEW IMAGE NAME>:<VERSION>
“docker commit ” is create new docker image by including all the changes.
This is the newly created docker image.
5. Push docker image to docker hub registry
We use “docker push” command for adding new image to docker hub.
docker push <PUBLIC REPOSITORY NAME>/<NEW IMAGE NAME>:<VERSION>
When we try to push docker image to docker hub it is denied. In this case it may be,
- docker doesn’t know where the exactly location is.
So you must have an docker hub registry account.
2. public repository is not exist.
Here, public repository is “test”. But we have only one namespace called “pramodshehan” in my docker hub registry.
Docker try to push that docker image to public repository called “test”. But public repository called “test” is not exist. That is why it may be denied.
6. Login docker hub registry.
Here we used “docker login” to login to docker registry.
docker login
After login, you can push that image to docker registry. Now docker know where the exactly location is.
After pushing, you can see new image in you docker hub registry.