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:
MAINTAINER myname <email@example.com>
RUN apt-get update
RUN apt-get -y upgrade
# By default, simply start a shell
Let us now run docker on the Dockerfile:
docker build -t myname:myLinux2 --rm=true .
A verbose output will follow.
- 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:
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