Verified Commit 4c1976d2 authored by Frere, Jonathan (FWCC) - 142176's avatar Frere, Jonathan (FWCC) - 142176
Browse files

Add example running Python container

parent 75d88a88
......@@ -4,7 +4,7 @@ date: 2020-08-25
authors:
- frere
layout: blogpost
title_image: headway-5QgIuuBxKwM-unsplash.jpg
title_image: docker-cover.png
categories:
- tutorial
tags:
......@@ -142,9 +142,9 @@ The first thing we get when we run this docker command is a series of messages a
1. First, Docker tries (and fails) to search the computer that it's running on for an already cached copy of a container called `hello-world:latest`.
The `:latest` part is called the tag, and roughly corresponds to the version of the relevant software that is installed on this container.
When no tag is specified, Docker defaults to "latest", which is usually the most recent build of a container.
2. Because it can't find the image, it "pulls" the image from an external repository -- in this case, [DockerHub](https://hub.docker.com/search?q=&type=image).
2. Because it can't find the image, it "pulls" the image from an external repository -- in this case, [Docker Hub](https://hub.docker.com/search?q=&type=image).
The `hello-world` container is actually part of the "standard library" of official Docker images, which is where the `library/` part comes from.
Normally, if we were to host our own images on DockerHub, we'd need to include a user or organisation namespace (e.g. `helmholtz/...`).
Normally, if we were to host our own images on Docker Hub, we'd need to include a user or organisation namespace (e.g. `helmholtz/...`).
3. The line beginning with a set of random numbers and digits means that Docker is downloading a layer.
(The numbers and digits are an identifier for the file being downloaded.)
On slower computers, you might see a loading bar appear here while the actual download takes place.
......@@ -156,6 +156,59 @@ The first thing we get when we run this docker command is a series of messages a
# Running Our Second Docker Container
The "Hello World" operation runs, but it doesn't actually do much useful --
let's try running something more interesting and useful.
Part of our original motivation for this exercise was managing the chaos of different ways of installing Python and its dependencies,
so let's see if we can get a container up and running with Python.
The first step is generally to find a Python base image.
Thankfully, as part of the set of officially mainained images, Docker provides some Python images for us to use.
This includes images for different versions of Python.
Whereas last time, we used the default `latest` tag, this time we can try explicitly using the 3.8.5 tag to set the Python version.
However, if we try running this, we'll run into a bit of an issue:
```console
$ docker run python:3.8.5
Unable to find image 'python:3.8.5' locally
3.8.5: Pulling from library/python
d6ff36c9ec48: Pull complete
c958d65b3090: Pull complete
edaf0a6b092f: Pull complete
80931cf68816: Pull complete
7dc5581457b1: Pull complete
87013dc371d5: Pull complete
dbb5b2d86fe3: Pull complete
4cb6f1e38c2d: Pull complete
c2df8846f270: Pull complete
Digest: sha256:bc765f71aaa90648de6cfa356ec201d50549031a244f48f8f477f386517c5d1b
Status: Downloaded newer image for python:3.8.5
$
```
If you run this, you'll immediately see that there are a lot more layers that need to be downloaded and extracted --
this makes sense, as Python is a much more complicated piece of software than just print a "Hello World" message!
You'll also see that instead of `latest`, the tag is `3.8.5`, so we can be sure what version we are using.
However, when we ran this image, the docker command immediately exited, and we're back to where we started.
We've downloaded _something_ -- but what does that something actually do?
By default, when Docker runs a container, it just prints the output of that container --
it doesn't send any user input into that container.
However, the default Python command is a REPL -- it require some sort of input to do something with.
To allow us to send terminal input in and out, we can use the `-it` flags, like this:
```console?prompt=$
$ docker run -it python:3.8.5
Python 3.8.5 (default, Sep 1 2020, 18:44:24)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
```
That looks better!
Feel free to play around and convince yourself that this is a working, standard Python installation.
# Next: Part 2 -- A Dockerfile Walkthrough
......
......@@ -4,7 +4,7 @@ date: 2020-08-25
authors:
- frere
layout: blogpost
title_image: headway-5QgIuuBxKwM-unsplash.jpg
title_image: docker-cover.png
categories:
- tutorial
tags:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment