Skip to content

Commit

Permalink
Merge pull request #242 from jcohen02/fix/issue228
Browse files Browse the repository at this point in the history
Adding solution and guidance to questions in advanced-containers.md
  • Loading branch information
aturner-epcc authored Aug 16, 2024
2 parents e631501 + 04d0220 commit 710abbc
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions episodes/advanced-containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,40 @@ container image.

## Running containers

What command would we use to run Python from the `alpine-python` container?
Question: What command would we use to run Python from the `alpine-python` container?


::::::::::::::: solution

## Solution

We can run a container from the alpine-python container image using:

```bash
$ docker container run alice/alpine-python
```

What happens? Since the `Dockerfile` that we built this container image from
had a `CMD` entry that specified `["python3", "--version"]`, running the above
command simply starts a container from the image, runs the `python3 --version`
command and exits. You should have seen the installed version of Python printed
to the terminal.

Instead, if we want to run an interactive Python terminal, we can use `docker
container run` to override the default run command embedded within the
container image. So we could run:

```bash
$ docker container run -it alice/alpine-python python3
```

The `-it` tells Docker to set up and interactive terminal connection to the
running container, and then we're telling Docker to run the `python3` command
inside the container which gives us an interactive Python interpreter prompt.
_(type `exit()` to exit!)_

:::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::

If we try running the container and Python script, what happens?
Expand All @@ -69,9 +100,12 @@ python3: can't open file '//sum.py': [Errno 2] No such file or directory

## No such file or directory

What does the error message mean? Why might the Python inside the container
Question: What does the error message mean? Why might the Python inside the container
not be able to find or open our script?

This question is here for you to think about - we explore the answer to this
question in the content below.

::::::::::::::::::::::::::::::::::::::::::::::::::

The problem here is that the container and its filesystem is separate from our
Expand Down

0 comments on commit 710abbc

Please sign in to comment.