Thursday, October 29, 2026
HomeCloud ComputingHow you can create a customized picture from a Docker container

How you can create a customized picture from a Docker container

[ad_1]

Getting your individual customized picture makes working with containers simpler and it provides an additional layer of safety. Jack Wallen reveals you the way.

How you can create a customized picture from a Docker container
Illustration: Lisa Hornung/TechRepublic

Your containers are all based mostly on pictures, most of which you in all probability pull from DockerHub or another public repository. However why not create your individual customized pictures? In any case, it’s simpler so that you can not solely get the precise picture it’s worthwhile to work with, it’s additionally a greater path to safety. It’s additionally a good way to create a base picture you need to use for a repeatable improvement surroundings (so, it has precisely the instruments you want).

SEE: 40+ open supply and Linux phrases it’s worthwhile to know (TechRepublic Premium)

I’m going to indicate you the way you are able to do simply that–create a picture from a container utilizing the Docker runtime engine.

What you’ll want

I’ll be demonstrating on Ubuntu Server 20.04, however you possibly can pull this off on any platform that helps Docker. The one factor you’ll want to change is the Docker set up course of. You’ll additionally want a person with sudo privileges (for the set up).

With that mentioned, let’s get to work.

How you can set up Docker

Let’s first get Docker put in. We’ll set up the newest model of the group version of Docker. Log into your server and set up the mandatory dependencies with:

sudo apt-get set up ca-certificates curl gnupg lsb-release -y

As soon as that completes, add the Docker GPG key:

curl -fsSL https://obtain.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Subsequent, add the Docker repository with the command:

echo 
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://obtain.docker.com/linux/ubuntu 
$(lsb_release -cs) secure" | sudo tee /and many others/apt/sources.checklist.d/docker.checklist > /dev/null

Replace apt and set up Docker-ce with:

sudo apt-get replace
sudo apt-get set up docker-ce docker-ce-cli containerd.io -y

Add your person to the Docker group with:

sudo usermod -aG docker $USER

Sign off and log again in for the adjustments to take impact.

How you can create your base container

We’re going to make use of the official Ubuntu picture to create our container (which might be used to create the brand new picture). Let’s pull down the newest model of Ubuntu from DockerHub and create a container named ubuntu-test with the command:

docker run -ti --name=ubuntu-test ubuntu:newest

At this level, it’s best to end up on the bash immediate of the operating Ubuntu container. Let’s say this new picture might be used for Java improvement. Set up the newest Java runtime surroundings. First replace apt with:

apt-get replace

Subsequent, set up the newest JRE with:

apt-get set up default-jre -y

After the set up completes, exit from the container with:

exit

How you can create the brand new picture

The very first thing to be achieved is to create a commit for the operating container. Do that with:

docker commit ubuntu-test

Subsequent, we have to find the container ID for our operating occasion with the command:

docker ps -a

Begin the container with:

docker begin ID

The place ID is the container ID for ubuntu-test.

Subsequent, we have to discover the picture ID with the command:

docker pictures

Once we made the commit earlier, it created a picture and not using a tag or title. You’ll see a picture listed with <none> as each the ID and title. That’s the picture we need to tag. Utilizing the primary 4 characters of the picture ID of the brand new picture, tag it with:

docker tag ID ubuntu-test-base

The place ID is the primary 4 characters of the container ID for ubuntu-test. Now, when you concern the command docker pictures, you’ll see your new picture with the title ubuntu-test-base. You can then deploy a brand new container, utilizing that new picture, with a command like:

docker create --name ubuntu-jre ubuntu-test-base

And that’s all there’s to making a customized Docker picture, based mostly on a modified container.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the newest tech recommendation for enterprise execs from Jack Wallen.

 

 

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments