Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to edit docker image in two ways

by | Nov 6, 2018

Spin up and run applications in split-seconds – That’s what makes Docker containers so popular among developers and web hosting providers.

In our role as Technical Support Providers for web hosting companies and infrastructure providers, we provision and manage Docker systems that best suit their purposes.

One of the key tasks involved in this Docker management services, is editing docker images. Today, we’ll see how we edit docker image for customer needs.

 

What is a docker image

Docker helps to easily create and run container instances with our desired applications. These containers are created using images.

A docker image is a package of code, libraries, configuration files, etc. for an application. The images are stored in repositories (storage locations).

Images can be downloaded from a repository and executed to create docker containers. So, in effect, a container is just a run-time instance of a particular image.

To create a Docker image, a Dockerfile is used. A dockerfile is a text document, usually saved in YAML format. It contains the list of commands to be executed to create an image.

 

How to edit docker image

The images provided by repositories are specific to a single instance type creation. In many scenarios, users need to edit these images to suit their needs.

For customizing or tweaking a docker image to specific requirements, we edit this docker image. But Docker has a drawback that an image cannot be directly edited or modified.

To edit Docker images, there are two ways:

 

1. Edit the Dockerfile

The most commonly used method is to edit the Dockerfile that is used to create the Docker image. This is a convenient and fool-proof method to edit docker image.

A sample Dockerfile for a Zabbix monitoring container would look like:

zabbix-agent: 
 container_name: zabbix-agent 
 image: zabbix/zabbix-agent:latest 
 net: "host" 
 privileged: true 
 restart: always 
 environment: 
   ZBX_SERVER_HOST: zabbix.mysite.com 

To modify the image used by an existing container, we delete that container, edit the Docker file with the changes needed and recreate the container with the new file.

In this sample Dockerfile, the image used to create the container is ‘zabbix/zabbix-agent:latest’. This image can be modified to another one or version by editing this file.

The ‘docker compose’ tool helps to manage multiple Docker containers easily using a single YAML Dockerfile. In cases where changes are to be made for only one container, it can be edited in the file.

After making changes to the image, only the corresponding containers need to be recreated and others can be left intact. The option “–no-recreate” is used for that.

docker-compose -f dockerfile.yml  up -d --no-recreate

 

As Docker containers are meant to be restarted and recreated, they cannot be used to store persistent data. The data in Docker infrastructure are usually stored in Docker volumes.

Storing the data in volumes outside the containers ensures that even when the containers are recreated, the data related to it won’t get affected.

This enables us to easily edit a docker image without losing the underlying data. Modifying Dockerfiles also helps to keep track of the changes made in the images.

Utmost care has to be exercised while modifying a Dockerfile, especially in the production environment, as a single mistake can mess up a normally functioning container.

 

2. Create a modified image

Another option to edit docker image is to run an existing image as a container, make the required modifications in it and then create a new image from the modified container.

a. First, create a Docker container from a parent image that is available in repository.

b. Then connect to the container via bash shell

docker exec -it container-name bash

c. From the shell, make the changes in the container as required. This can include installing new packages, modifying configuration files, downloading or removing files, compiling modules, and so on.

d. Once the changes are done, exit the container. Then commit the container as a new image. This will save the modified container state as a new image.

docker commit container-ID image-name

 

e. This modified image is then uploaded to a repository, which is then used for creating more such containers for future use.

 

Conclusion

Docker containers are widely used in DevOps and niche web hosting. Today we’ve discussed how our Docker Support Engineers easily edit docker images in our Docker infrastructure management.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

2 Comments

  1. Sagar

    I can change container no

    Reply
  2. Azman

    Thanks

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF