Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Docker Tutorials: Image – Creating Docker Image Step by Step

Setting up the prerequisites

Listing images on the host

$ docker images

If you do not have ubuntu:14.04 images, please download it using following commands.

$ docker pull ubuntu:14.0 

Verify the ubuntu:14.0 image by running the following commands.

$ docker run -t -i -d ubuntu:14.04 /bin/bash

Method 1: You can update a container created from an image and commit the results to an image.

We will use training/sinatra image pretty useful for creating the images for Method1.

To update an image you first need to create a container from the image you’d like to update.

$ docker run -t -i training/sinatra /bin/bash

Inside our running container first let’s update apt, httpd and install git.

$ root@0b2616b0e5a8:/# apt-get updateCode language: PHP (php)
$ root@0b2616b0e5a8:/# apt-get install -y gitCode language: PHP (php)
$ root@0b2616b0e5a8:/# apt-get install -y httpdCode language: PHP (php)

Once this has completed let’s exit our container using the exit command. Now you have a container with the change you want to make. You can then commit a copy of this container to an image using the docker commit command.

$ docker commit -m "Added json gem" -a "Rajesh Kumar" 0b2616b0e5a8 scmgalaxy/sinatra:v2Code language: JavaScript (javascript)

Here you’ve used the docker commit command. You’ve specified two flags: -m and -a. The -m flag allows us to specify a commit message, much like you would with a commit on a version control system. The -a flag allows us to specify an author for our update.

You’ve also specified the container you want to create this new image from, 0b2616b0e5a8 (the ID you recorded earlier) and you’ve specified a target for the image:scmgalaxy/sinatra:v2

It consists of a new user, scmgalaxy, that you’re writing this image to. You’ve also specified the name of the image sinatra. Finally you’re specifying a tag for the image: v2.

You can then look at our new scmgalaxy/sinatra image using the docker images command.

$ docker images

To use our new image to create a container you can then:

$ docker run -t -i ouruser/sinatra:v2 /bin/bash

Method 2: You can use a Dockerfile to specify instructions to create an image.

Using the docker commit command is a pretty simple way of extending an image but it’s a bit cumbersome and it’s not easy to share a development process for images amongst a team. Instead you can use a new command, docker build, to build new images from scratch.

To do this you create a Dockerfile that contains a set of instructions that tell Docker how to build our image.

First, create a directory and a Dockerfile.


$ mkdir sinatra
$ cd sinatra
$ touch Dockerfile

Each instruction creates a new layer of the image. Try a simple example now for building your own Sinatra image for your fictitious development team.


FROM ubuntu:14.04
MAINTAINER Rajesh Kumar "rajesh@scmgalaxy.com"
RUN apt-get update && apt-get install -y git httpd
Code language: JavaScript (javascript)

Examine what your Dockerfile does. Each instruction prefixes a statement and is capitalized.

INSTRUCTION statement

The first instruction FROM tells Docker what the source of our image is, in this case you’re basing our new image on an Ubuntu 14.04 image. The instruction uses the MAINTAINER instruction to specify who maintains the new image.

Lastly, you’ve specified two RUN git and httpd

Now let’s take our Dockerfile and use the docker build command to build an image.

$ docker build -t scmgalaxy/sinatra:v3 ./ 

You’ve specified our docker build command and used the -t flag to identify our new image as belonging to the user scmgalaxy, the repository name sinatra and given it the tag v2.

$ docker run -t -i scmgalaxy/sinatra:v2 /bin/bash/ 

Setting tags on an image

$ docker tag 5db5f8471261 scmgalaxy/sinatra:dev

The docker tag command takes the ID of the image, here 5db5f8471261, and our user name, the repository name and the new tag.

$ docker images scmgalaxy/sinatra

Remove an image from the host

$ docker rmi training/sinatra

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Here’s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Here’s an in-depth, step-by-step tutorial and lab manual for Docker Networking—starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x