[GH-ISSUE #202] asciinema rec doesn't work in a Docker container #147

Closed
opened 2026-02-25 20:32:49 +03:00 by kerem · 5 comments
Owner

Originally created by @philippgille on GitHub (Apr 1, 2017).
Original GitHub issue: https://github.com/asciinema/asciinema/issues/202

asciinema rec doesn't work in a Docker container. Probably due to the Dockter container TTY being "pseudo"?

Reproduce:

  1. docker run -it ubuntu:16.04 bash
  2. apt update && apt upgrade -y
  3. apt install asciinema -y
  4. asciinema rec
~ Asciicast recording started.
~ Hit ctrl+d or type "exit" to finish.

Traceback (most recent call last):
  File "/usr/bin/asciinema", line 9, in <module>
    load_entry_point('asciinema==0.9.8', 'console_scripts', 'asciinema')()
  File "/usr/lib/python3/dist-packages/asciinema/__main__.py", line 7, in main
    get_command(sys.argv[1:], Config()).execute()
  File "/usr/lib/python3/dist-packages/asciinema/commands/record.py", line 23, in execute
    asciicast = self._record_asciicast()
  File "/usr/lib/python3/dist-packages/asciinema/commands/record.py", line 35, in _record_asciicast
    asciicast = self.recorder.record(self.cmd, self.title)
  File "/usr/lib/python3/dist-packages/asciinema/recorder.py", line 16, in record
    cmd or self.env['SHELL'])
  File "/usr/lib/python3.5/os.py", line 725, in __getitem__
    raise KeyError(key) from None
KeyError: 'SHELL'
Originally created by @philippgille on GitHub (Apr 1, 2017). Original GitHub issue: https://github.com/asciinema/asciinema/issues/202 `asciinema rec` doesn't work in a Docker container. Probably due to the Dockter container TTY being "pseudo"? Reproduce: 1. `docker run -it ubuntu:16.04 bash` 1. `apt update && apt upgrade -y` 1. `apt install asciinema -y` 1. `asciinema rec` ``` ~ Asciicast recording started. ~ Hit ctrl+d or type "exit" to finish. Traceback (most recent call last): File "/usr/bin/asciinema", line 9, in <module> load_entry_point('asciinema==0.9.8', 'console_scripts', 'asciinema')() File "/usr/lib/python3/dist-packages/asciinema/__main__.py", line 7, in main get_command(sys.argv[1:], Config()).execute() File "/usr/lib/python3/dist-packages/asciinema/commands/record.py", line 23, in execute asciicast = self._record_asciicast() File "/usr/lib/python3/dist-packages/asciinema/commands/record.py", line 35, in _record_asciicast asciicast = self.recorder.record(self.cmd, self.title) File "/usr/lib/python3/dist-packages/asciinema/recorder.py", line 16, in record cmd or self.env['SHELL']) File "/usr/lib/python3.5/os.py", line 725, in __getitem__ raise KeyError(key) from None KeyError: 'SHELL' ```
kerem 2026-02-25 20:32:49 +03:00
Author
Owner

@ku1ik commented on GitHub (Apr 5, 2017):

It expects SHELL env var. You can try: env SHELL=/bin/sh asciinema rec.
Btw, this 0.9.8 version of asciinema is over 2 years old. I suggest installing the latest one: https://asciinema.org/docs/installation

<!-- gh-comment-id:291964538 --> @ku1ik commented on GitHub (Apr 5, 2017): It expects `SHELL` env var. You can try: `env SHELL=/bin/sh asciinema rec`. Btw, this `0.9.8` version of asciinema is over 2 years old. I suggest installing the latest one: https://asciinema.org/docs/installation
Author
Owner

@philippgille commented on GitHub (Apr 5, 2017):

I had been on that website, but I used the command listed for Debian instead of Ubuntu.

For Ubuntu, in the Docker container, I additionally had to apt-get install software-properties-common before being able to apt-add-repository ppa:zanchey/asciinema. Now it shows version 1.3.0-1.

But now, when I do asciinema rec it shows:

Traceback (most recent call last):
  File "/usr/bin/asciinema", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'

echo $SHELL shows /bin/bash.

env SHELL=/bin/sh asciinema rec leads to the same error.

On Stackoverflow I found a question regarding the error and tried apt-get install --reinstall python-pkg-resources, but it didn't help. Another answer to that question suggested pip install --upgrade setuptools, where I had to apt-get install python-pip before. Still the same error.

Another answer suggested apt-get install python3-setuptools.

Now, finally asciinema rec gave me different ouput: asciinema needs a UTF-8 native locale to run. Check the output of locale command.. Typically a fresh Ubuntu container doesn't have any locales set up. So I did locale-gen en_US.UTF-8 and export LANG=en_US.UTF-8 and export LANGUAGE=en_US:en and export LC_ALL=en_US.UTF-8 (maybe in a different order).

And that fixed it for me. I can now asciinema rec!

You might want to prevent other Docker users to go through this, so maybe the installer can be improved regarding the No module named 'pkg_resources' issue, or you could add a Ubuntu Docker container section on your Installation page.

<!-- gh-comment-id:291982947 --> @philippgille commented on GitHub (Apr 5, 2017): I had been on that website, but I used the command listed for *Debian* instead of Ubuntu. For Ubuntu, in the Docker container, I additionally had to `apt-get install software-properties-common` before being able to `apt-add-repository ppa:zanchey/asciinema`. Now it shows version `1.3.0-1`. But now, when I do `asciinema rec` it shows: ``` Traceback (most recent call last): File "/usr/bin/asciinema", line 5, in <module> from pkg_resources import load_entry_point ImportError: No module named 'pkg_resources' ``` `echo $SHELL` shows `/bin/bash`. `env SHELL=/bin/sh asciinema rec` leads to the same error. On Stackoverflow I found a [question regarding the error](http://stackoverflow.com/questions/7446187/no-module-named-pkg-resources) and tried `apt-get install --reinstall python-pkg-resources`, but it didn't help. Another answer to that question suggested `pip install --upgrade setuptools`, where I had to `apt-get install python-pip` before. Still the same error. Another answer suggested `apt-get install python3-setuptools`. Now, finally `asciinema rec` gave me different ouput: `asciinema needs a UTF-8 native locale to run. Check the output of `locale` command.`. Typically a fresh Ubuntu container doesn't have any locales set up. So I did `locale-gen en_US.UTF-8` and ` export LANG=en_US.UTF-8` and `export LANGUAGE=en_US:en` and `export LC_ALL=en_US.UTF-8` (maybe in a different order). And *that* fixed it for me. I can now `asciinema rec`! You might want to prevent other Docker users to go through this, so maybe the installer can be improved regarding the `No module named 'pkg_resources'` issue, or you could add a *Ubuntu Docker container* section on your [Installation page](https://asciinema.org/docs/installation).
Author
Owner

@ku1ik commented on GitHub (Apr 11, 2017):

Kudos for figuring this all out! I'm not sure how many people record from within containers, but let's just leave this issue open and see if/how many people come here.

I'm also thinking about creating official asciinema cli container. Once we have that, we can add Docker section to README, also explaining what's needed when you're manually installing asciinema inside of a container.

<!-- gh-comment-id:293311124 --> @ku1ik commented on GitHub (Apr 11, 2017): Kudos for figuring this all out! I'm not sure how many people record from within containers, but let's just leave this issue open and see if/how many people come here. I'm also thinking about creating official asciinema cli container. Once we have that, we can add Docker section to README, also explaining what's needed when you're manually installing asciinema inside of a container.
Author
Owner

@evertramos commented on GitHub (Aug 23, 2017):

I have this container as a test:

FROM ubuntu

RUN apt-get update && apt-get install -y \
    asciinema \
    && rm -rf /var/lib/apt/lists/*

# Install utf8 locale
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
    && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# Update asciinema version
RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/

It's working for me.

<!-- gh-comment-id:324325302 --> @evertramos commented on GitHub (Aug 23, 2017): I have this container as a test: ``` FROM ubuntu RUN apt-get update && apt-get install -y \ asciinema \ && rm -rf /var/lib/apt/lists/* # Install utf8 locale RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 # Update asciinema version RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ ``` It's working for me.
Author
Owner

@philippgille commented on GitHub (Aug 28, 2017):

I don't think that's a valid, working Dockerfile. It's using wget, but wget isn't part of ubuntu:16.04 and it's not being installed either.

docker build -t local/asciinema-test . with that Dockerfile leads to:

Step 5/5 : RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/
 ---> Running in 22b12a27d4cd
/bin/sh: 1: wget: not found
The command '/bin/sh -c wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/' returned a non-zero code: 127

As expected.

Also I would combine the first two RUN commands, otherwise apt-get update, then rm -rf /var/lib/apt/lists/* and then apt-get update again leads to unnecessary overhead.

And installing asciinema from the Ubuntu package repository isn't necessary when overwriting it with the version from GitHub anyway.

So, trying with this improved Dockerfile:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y \
    locales \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Install utf8 locale
RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

# Update asciinema version
RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz \
    && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz \
    && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ \
    && rm asciinema-1.2.0-linux-amd64.tar.gz

That worked for me.

Thanks for the hints though @evertramos!

Also, in case you're already inside an existing container and you want to record something, the steps are similar to the Dockerfile:

apt-get update && apt-get install -y \
    locales \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Install utf8 locale
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
export LANG=en_US.utf8

# Update asciinema version
wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz \
    && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz \
    && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ \
    && rm asciinema-1.2.0-linux-amd64.tar.gz

Also please also be aware of the official documentation: https://asciinema.org/docs/installation#running-in-docker-container

That documentation didn't exist when I opened this issue. I'd recommend to stick to the official Docker image.


Regarding this ticket: I think it can be closed.

<!-- gh-comment-id:325493266 --> @philippgille commented on GitHub (Aug 28, 2017): I don't think that's a valid, working Dockerfile. It's using `wget`, but `wget` isn't part of `ubuntu:16.04` and it's not being installed either. `docker build -t local/asciinema-test .` with that Dockerfile leads to: ``` Step 5/5 : RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ ---> Running in 22b12a27d4cd /bin/sh: 1: wget: not found The command '/bin/sh -c wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/' returned a non-zero code: 127 ``` As expected. Also I would combine the first two `RUN` commands, otherwise `apt-get update`, then `rm -rf /var/lib/apt/lists/*` and then `apt-get update` again leads to unnecessary overhead. And installing `asciinema` from the Ubuntu package repository isn't necessary when overwriting it with the version from GitHub anyway. So, trying with this improved Dockerfile: ``` FROM ubuntu:16.04 RUN apt-get update && apt-get install -y \ locales \ wget \ && rm -rf /var/lib/apt/lists/* # Install utf8 locale RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 ENV LANG en_US.utf8 # Update asciinema version RUN wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz \ && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz \ && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ \ && rm asciinema-1.2.0-linux-amd64.tar.gz ``` *That* worked for me. Thanks for the hints though @evertramos! Also, in case you're already inside an existing container and you want to record something, the steps are similar to the Dockerfile: ``` apt-get update && apt-get install -y \ locales \ wget \ && rm -rf /var/lib/apt/lists/* # Install utf8 locale localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 export LANG=en_US.utf8 # Update asciinema version wget https://github.com/asciinema/asciinema/releases/download/v1.2.0/asciinema-1.2.0-linux-amd64.tar.gz \ && tar -xzf asciinema-1.2.0-linux-amd64.tar.gz \ && mv asciinema-1.2.0-linux-amd64/asciinema /usr/bin/ \ && rm asciinema-1.2.0-linux-amd64.tar.gz ``` **Also please also be aware of the official documentation: [https://asciinema.org/docs/installation#running-in-docker-container](https://asciinema.org/docs/installation#running-in-docker-container)** That documentation didn't exist when I opened this issue. I'd recommend to stick to the official Docker image. ---- Regarding this ticket: I think it can be closed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asciinema#147
No description provided.