docker ubuntu with python and git

To get the image

docker pull ubuntu

After an image has been downloaded, you may then run a container using the downloaded image with the run subcommand. If an image has not been downloaded when docker is executed with the run subcommand, the Docker client will first download the image, then run a container using it:

docker run ubuntu

To see the images

docker images

To run the image with interactive shell

docker run -it ubuntu

Update Ubuntu

Inside the Shell type

apt-get update
apt-get install python3

After a short while this should be setup.

Loose the Changes

If we close the Docker image, all the changes will be lost !!

Keep the Changes

Knowing that the changes will be lost, we can use another shell - and issue the command

docker ps

We should see something like

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
172a7558fdba        ubuntu              "/bin/bash"         2 minutes ago       Up 2 minutes                            eloquent_cori

As we want to keep the changes that we have made - we type.

docker commit 172a7558fdba ubuntu:python3

In the shell we can now exit.

Show the Containers

To show what containers we now have

docker image ls

and I now see

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              python3             18cb64bd27ec        5 hours ago         155MB
ubuntu              latest              452a96d81c30        2 weeks ago         79.6MB

Run the New Container

We seem to have a container, called ubuntu/python3

So lets run this

docker run -it ubuntu:python3

The easiest thing to try is python3 -V

root@647645241ca4:/# python3 -V
Python 3.6.5

And there we have it - python3 is installed in our container.

This is OK but there is no pip3 installed, which is not good.

Docker File for a Build

Define a container with Dockerfile Dockerfile defines what goes on in the environment inside your container. Access to resources like networking interfaces and disk drives is virtualized inside this environment, which is isolated from the rest of your system, so you need to map ports to the outside world, and be specific about what files you want to “copy in” to that environment. However, after doing that, you can expect that the build of your app defined in this Dockerfile behaves exactly the same wherever it runs.

FROM ubuntu:16.04

RUN apt-get update -y && \
  apt-get install python3-pip idle3 -y && \
  pip3 install --no-cache-dir --upgrade pip && \
  \
  # delete cache and tmp files
  apt-get clean && \
  apt-get autoclean && \
  rm -rf /var/cache/* && \
  rm -rf /tmp/* && \
  rm -rf /var/tmp/* && \
  rm -rf /var/lib/apt/lists/* && \
  \
  # make some useful symlinks that are expected to exist
  cd /usr/bin && \
  ln -s idle3 idle && \
  ln -s pydoc3 pydoc && \
  ln -s python3 python && \
  ln -s python3-config python-config && \
  cd /

Building Image

To build the image we issue

 docker build -t dockerfile .

There is quite a bit of output - we can check

the image by

dock image ls 

I see the dockerfile which was the name of the creation file.

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
dockerfile          latest              6b93becbbdfb        About an hour ago   421MB
jenkins             initial_setup       226b2c534fc3        3 days ago          800MB
jenkins             latest              0f178e3827f0        11 days ago         798MB
ubuntu              16.04               0b1edfbffd27        2 weeks ago         113MB
ubuntu              latest              452a96d81c30        2 weeks ago         79.6MB
hello-world         latest              e38bc07ac18e        4 weeks ago         1.85kB

Now to run the image

docker run -it dockerfile