Docker tutorials 3: creating an image with a Dockerfile

We will do the same creation process as in tutorial 1 by using a Dockerfile.

By using any editor, let’s create in our working directory in the host machine a file named Dockerfile with the following content:

FROM ubuntu:latest
MAINTAINER myname <myname@mydomain.com>
RUN apt-get update
RUN apt-get -y upgrade
# By default, simply start a shell
CMD /bin/bash

Let us now run docker on the Dockerfile:

docker build -t myname:myLinux2 --rm=true .

A verbose output will follow.

Note:

  • myname:myLinux2 is the name of the created image.
  • –rm=true will remove intermediate containers created along the process.

We can now check that the image has been created:

docker images
REPOSITORY                     TAG                 IMAGE ID           CREATED             SIZE
myname                        myLinux2           50ee9e4f504d       13 minutes ago     215.9 MB

let’s start the image, running the default command and attaching the terminal:

docker run -it myname:myLinux2
#

Alternatively, we could have started the image, running an alternate command and attaching the terminal:

docker run -it myname:myLinux2 /bin/ls
bin   dev home lib64  mnt proc run  srv tmp var
boot etc lib media    opt root sbin sys usr

We get back to the host machine, since after running ls the docker machine has finishes

References:

Docker build:

Advertisements
Tagged with:
Posted in Docker

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: