How to create a custom image from a Docker container

Illustration: Lisa Hornung/TechRepublic
Your containers are all based on images, most of which you probably pull from DockerHub or some other public repository. Its also a great method to develop a base image you can utilize for a repeatable advancement environment (so, it has exactly the tools you need).

Getting your own customized image makes working with containers easier and it includes an additional layer of security. Jack Wallen shows you how.

Open source: Must-read coverage

Your containers are all based on images, most of which you most likely pull from DockerHub or some other public repository. Its also a great method to produce a base image you can use for a repeatable advancement environment (so, it has precisely the tools you need).

.

Utilizing the very first 4 characters of the image ID of the brand-new image, tag it with:.
Now, if you provide the command docker images, youll see your new image with the name ubuntu-test-base. You might then deploy a new container, utilizing that new image, with a command like:.

SEE: 40+ open source and Linux terms you need to understand (TechRepublic Premium).
Im going to reveal you how you can do simply that– create an image from a container using the Docker runtime engine.
What youll need.
Ill be demonstrating on Ubuntu Server 20.04, but you can pull this off on any platform that supports Docker. The only thing youll need to alter is the Docker setup process. Youll likewise need a user with sudo opportunities (for the setup).
With that stated, lets get to work.
How to install Docker.
Lets first get Docker set up. Well install the current variation of the neighborhood edition of Docker. Log into your server and set up the necessary dependencies with:.
sudo apt-get install ca-certificates curl gnupg lsb-release -y.
When that finishes, include the Docker GPG secret:.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg|sudo gpg– dearmor -o/ usr/share/keyrings/ docker-archive-keyring. gpg.
Next, include the Docker repository with the command:.
echo.
$( lsb_release -cs) steady”|sudo tee/ etc/apt/sources. list.d/ docker.list > >/ dev/null.
Update apt and install Docker-ce with:.
sudo apt-get update.
sudo apt-get set up docker-ce docker-ce-cli containerd.io -y.
Add your user to the Docker group with:.
sudo usermod -aG docker $USER.
Log out and log back in for the changes to work.
How to create your base container.
Were going to use the main Ubuntu image to create our container (which will be used to develop the new image). Lets take down the most recent variation of Ubuntu from DockerHub and create a container called ubuntu-test with the command:.
docker run -ti– name= ubuntu-test ubuntu: most current.
At this point, you should discover yourself at the bash timely of the running Ubuntu container. Lets say this new image will be utilized for Java development.
apt-get upgrade.
Next, set up the most recent JRE with:.
apt-get set up default-jre -y.
After the setup completes, exit from the container with:.
exit.
How to produce the brand-new image.
The very first thing to be done is to create a commit for the running container. Do this with:.
docker dedicate ubuntu-test.
Next, we need to locate the container ID for our running instance with the command:.
docker ps -a.
Start the container with:.
docker start ID.
Where ID is the container ID for ubuntu-test.
Next, we require to discover the image ID with the command:.
docker images.
When we made the devote earlier, it produced an image without a tag or name. Youll see an image listed with << none> > as both the ID and name. Thats the image we desire to tag. Utilizing the very first 4 characters of the image ID of the brand-new image, tag it with:.
docker tag ID ubuntu-test-base.
Where ID is the first 4 characters of the container ID for ubuntu-test. Now, if you release the command docker images, youll see your brand-new image with the name ubuntu-test-base. You might then deploy a new container, utilizing that brand-new image, with a command like:.
docker produce– name ubuntu-jre ubuntu-test-base.
And thats all there is to producing a custom-made Docker image, based upon a customized container.
Subscribe to TechRepublics How To Make Tech Work on YouTube for all the latest tech suggestions for company pros from Jack Wallen

Share:

Leave a Comment