Creating a new Docker Image/container from existing Container

Share via:

Creating a new Docker Image/container from existing Container

And run the new container.
Step 1: Create an initial Base Container – for an App
▪️ Let’s get started by creating a running container.
▪️ So that we don’t get bogged down in the details of any particular container,
▪️ We can use nginx.
▪️ The Docker create command will create a new container.

Step 2: Inspect Images
▪️ If you look at the list of images on your system
▪️ You will now see the nginx:alpine image:
docker images -a

Step 3: Inspect Containers- created but not started.
▪️ Note here that the container is not running.
▪️ So, you won’t see it in the container list unless you use the -a flag (-a is for all).

Step 4: Start the container – which should expose port 80.
▪️ Let’s start the container and see what happens.

Step 5: Access the container App – from browser with localhost:
▪️ The browser will show the default message “Welcome to nginx”

Step 6: Modify the Running Container – by creating index.html.
▪️ Create a file index.html with content “Hello World” in the local directory in local host.
▪️ And copy this file into container location /usr/share/nginx/html/index.html

Step 7: Commit the Running Container nginx_base.
▪️ Create a new image using the commit command.
$ docker commit nginx_base
sha256:284608bfc7628ea86036fbbac9cbf0038dcb2322f161a8730e630ee6c29e44a4

Step 8: Create the TAG for the newly created image:
docker tag 284608bfc762 hello_world_nginx
Step 9: Stop and remove the initial base container which is running.
Step 10: Start the new App container with the new image.
▪️ Create and start the new container using the run command.
docker run –name hello_world -p 80:80 hello_world_nginx

Step 11: Access the new App container.
from browser with localhost:
▪️ The browser will show the new message “Hello World”
▪️ This is as per modified container image, where we added the index.html with “Hello World” message.
Drawbacks of Using Docker Containers
Some of the drawbacks of using Docker containers include:
👉 Security concerns:
Containers share the host operating system, so if a container is compromised, the host can also be affected. This is why proper measures must be taken to ensure the security of containers.
👉 Limited Resource Management:
Containers rely on the host for resource management, so there may be limitations on the resources available to each container, such as CPU, memory, and storage.
👉 Networking Complexity:
Networking between containers can be complex, especially in multi-host deployments.
👉 Persistent Storage:
 Persistent storage can be a challenge with containers, as containers are ephemeral by nature and data can be lost when a container is deleted or recreated.
👉 Scalability:
 Scaling containers can be difficult, as each container runs in isolation, and multiple containers must be coordinated to scale an application.
👉 Support for Legacy Applications:
 Legacy applications that are not designed to run in containers may not work well in a containerized environment.
These are some of the challenges that can be faced while using Docker containers, but with proper planning and management, these challenges can be overcome to achieve the benefits of containerization.

 

 

Author    : Venkat Vinod Kumar Siram 
LinkedIn : https://www.linkedin.com/in/vinodsiram/
Assisted by Shanmugavel
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook  : https://www.facebook.com/ktexperts
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform
Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment