DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Customizing Docker Images

Customizing Docker Images

If you want to make changes to your Docker images, check out this tutorial that shows you how to edit a running image.

Amanuel G. Shiferaw user avatar by
Amanuel G. Shiferaw
CORE ·
Jan. 28, 19 · Tutorial
Like (2)
Save
Tweet
Share
6.11K Views

Join the DZone community and get the full member experience.

Join For Free

Back in the day, when I was beginning to work on public-facing projects, setting up a development environment was really tedious. You have to install all the required software’s on the host machine. Relocating a project from one host to another sometimes comes to be the real work.

Now, the trend seems to have been changed. Once you want to work on a project, you start setting up a virtual machine on a remote computer that your company provides or a local virtual machine (at least in my company people prefer to work on virtual machines). There are many benefits, but one that I use all the time is the ability to take a virtual machine from one host and run it on a different one. Other than that, the ability to have multiple operating systems is very valuable for both development and testing.

In my company, we use the Windows systems for development purposes, but the client we are working for uses a Linux machine, which brought some unprecedented issues (since we are working on different platforms, every time we have to test for both environments). So as to align ourselves, we had to dedicate a full Linux server with Centos 7 and different application and web servers. While running some applications, we had a low response time and sometimes the complete death of some applications. Which finally led us to containerization.

There are many alternatives, even though we choose Docker. Docker is container technology with most public traction and is almost a de facto container standard right now. Docker containers wrap a piece of software in a complete file system that contains everything needed to run: code, system tools, system libraries and so on. This guarantees that the software will always run the same, regardless of its environment (host operating system).

In this post, I don’t go in details about how Docker works. I assume that you have it installed and have basic knowledge on how it works. I will try to cover how to edit and commit on a running image when we have to install/update configurations and/or software.

By default, once an image is created, it will stay as it is unless we commit new changes.

I start by downloading a Tomcat image from the official distribution (check on Dockerhub) and add a user to manage it so as to show how to do something very basic.

  1. Search for the image using image search command: $docker search tomcat

Image title Pull the image you prefer ($docker pull tomcat). This pulls the latest available image.$docker pull tomcat

Once the download has finished, run the container instance with:

$docker run -d -p 8888:8080 tomcat

where,

  • –d tells Docker to run the container in a daemon mode (in the background so that we can use our terminal window without the need to open a new one)
  • –p tells what port on the docker image(8080) should be accessed from the host and on what port(8888) . Running this command will give us something similar to:$docker run -d -p 8888:8080 tomcat
  1. Now we have Tomcat up and running on http://localhost:8888/ but we are still unable to login through the management-gui to manage the server. Let’s add a user to be able to do so.
docker exec -it {container} bash


 , where  container  is the container-id or container-name

  • –i interactive: Keep STDIN open even if not attached
  • –t Allocate a pseudo-TTY: we need this especially if we use a sudo commanddocker exec -it {container} bash

And add the following to “conf\tomcat-users.xml”. Before you can install and use your favorite editor. In my case it’s vim ( apt-get install vim ):

<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>


Exit from the shell.

Before stopping the container commit:

$docker commit container-id image-name:tag

 

You can change this if you need. Also, note the image-name and tag can be any name you like.Tomcat user add


Now you have a new image with everything from the previous one plus your setting. Note that if you exit the container before commit all the changes will be lost.

Try to run the new image and check if you can login the management-gui with the user created, use command:

docker run -d -p 8888:8080 tomcat:custom 


Note: After adding a user to Tomcat, if 403 Access Denied is not resolved, try changing the following in webapps/manager/META-INF/context.xml and commit again (you can use the same image-name:tag to overwrite the previous) :

<Context privileged="true">          
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1"/> -->
 </Context>



Docker (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why It Is Important To Have an Ownership as a DevOps Engineer
  • How To Use Terraform to Provision an AWS EC2 Instance
  • Using JSON Web Encryption (JWE)
  • Beginners’ Guide to Run a Linux Server Securely

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: