User Tools

Site Tools


docker:images:update_and_commit_an_image

Docker - Images - Update and Commit an Image

Pull an image

For example, to pull the Ubuntu 20.04 Docker image from the Docker Hub.

docker pull ubuntu:20.04

Create a new container

Create a new container from the Ubuntu 20.04 image.

docker run -t -i ubuntu:20.04 /bin/bash

This will create a new container and attach to the bash shell as shown below:

root@013aecdd6919:/#

Install NginX into the Container

Install the Nginx package inside the container:

root@013aecdd6919:/# apt-get update -y
root@013aecdd6919:/# apt-get install nginx -y

Exit from the Container

root@013aecdd6919:/# exit

Obtain the Container ID

Locate your new container ID:

docker ps -a

returns:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
013aecdd6919        ubuntu:20.04        "/bin/bash"         3 minutes ago       Exited (0) 33 seconds ago                        happy_camper

Save the Updated Container

Save the updated container with a new image named nginx-instance:

docker commit "013aecdd6919" nginx-instance
  • Where: 013aecdd6919 is the ID of the container.

Verify the newly created Image

Verify the newly created image “nginx-instance”:

docker images

returns:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx-instance      latest              12cefc9b5362        57 seconds ago      158MB
ubuntu              20.04               d70eaf7277ea        12 days ago         72.9MB

Log in to the Docker Hub

NOTE: In order to work with the Docker Hub, you will need to create an account on Docker Hub.

docker login

returns:

Username: peter
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
 
Login Succeeded

Tag the Image to push to the Docker Hub

For example, to tag the nginx-instance image:

docker tag 12cefc9b5362 peter/nginx-instance:ubuntu

where:

  • 12cefc9b5362 is the ID of the nginx-instance image.
  • peter is your Docker Hub username.
  • nginx-instance is the name of the image that you want to push.

Verify the Tagged Image

docker images

returns:

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
peter/nginx-instance       ubuntu              12cefc9b5362        12 minutes ago      158MB
nginx-instance             latest              12cefc9b5362        12 minutes ago      158MB
ubuntu                     20.04               d70eaf7277ea        12 days ago         72.9MB

Push the new Image to the Docker Hub

Push the new image named peter/nginx-instance to the Docker Hub:

docker push peter/nginx-instance

Login to the Docker Hub

Login to the Docker Hub using your web browser and verify that the nginx-instance image appears in the Repositories.

docker/images/update_and_commit_an_image.txt · Last modified: 2020/11/11 10:25 by 192.168.1.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki