Home > Blockchain >  The container becomes different from the container created with run
The container becomes different from the container created with run

Time:10-06

When I create a container using docker run I get the expected result - a container with all the packages installed. Run only When I exit the container (without changing anything) and try to enter it again using docker exec, it doesn't have the packages installed. After execCan Someone explain why this happens?

ubuntu@DESKTOP:~$ docker pull ciscotestautomation/pyats:latest
latest: Pulling from ciscotestautomation/pyats
Digest: sha256:7e1134ee4c7bb0d78f5aec0b71414cf1ac79026fc4757203bf29b88af24b1a03
Status: Image is up to date for ciscotestautomation/pyats:latest
docker.io/ciscotestautomation/pyats:latest

ubuntu@DESKTOP:~$ docker run --name=run_only -it ciscotestautomation/pyats:latest /bin/bash
[Entrypoint] Starting pyATS Docker Image ...
[Entrypoint] Workspace Directory: /pyats
[Entrypoint] Activating workspace
root@34db091e8cf4:/pyats# pip list
Package              Version
-------------------- -----------
aiofiles             0.7.0
aiohttp              3.7.4.post0
aiohttp-swagger      1.0.15
async-lru            1.0.2
async-timeout        3.0.1
attrs                21.2.0
certifi              2021.5.30
cffi                 1.14.6
chardet              4.0.0
charset-normalizer   2.0.6
cryptography         3.4.8
dill                 0.3.4
distro               1.6.0
idna                 3.2
idna-ssl             1.1.0
Jinja2               2.11.3
junit-xml            1.9
MarkupSafe           1.1.1
multidict            5.1.0
pathspec             0.9.0
pip                  21.2.4
psutil               5.8.0
pyats                21.9
pyats.aereport       21.9
pyats.aetest         21.9
pyats.async          21.9
pyats.connections    21.9
pyats.datastructures 21.9
pyats.easypy         21.9
pyats.kleenex        21.9
pyats.log            21.9
pyats.reporter       21.9
pyats.results        21.9
pyats.tcl            21.9
pyats.topology       21.9
pyats.utils          21.9
pycparser            2.20
python-engineio      3.14.2
python-socketio      4.6.1
PyYAML               5.4.1
requests             2.26.0
setuptools           58.1.0
six                  1.16.0
typing-extensions    3.10.0.2
unicon               21.9
unicon.plugins       21.9
urllib3              1.26.7
wheel                0.37.0
yamllint             1.26.3
yarl                 1.6.3
root@34db091e8cf4:/pyats# exit
exit

ubuntu@DESKTOP:~$ docker ps -a
CONTAINER ID   IMAGE                              COMMAND                  CREATED             STATUS                     PORTS     NAMES
34db091e8cf4   ciscotestautomation/pyats:latest   "/bin/tini -- /entry…"   14 seconds ago      Exited (0) 4 seconds ago             run_only

ubuntu@DESKTOP:~$ docker start run_only
run_only

ubuntu@DESKTOP:~$ docker ps -a
CONTAINER ID   IMAGE                              COMMAND                  CREATED             STATUS             PORTS     NAMES
34db091e8cf4   ciscotestautomation/pyats:latest   "/bin/tini -- /entry…"   36 seconds ago      Up 2 seconds                 run_only

ubuntu@DESKTOP:~$ docker exec -it run_only "/bin/bash"
root@34db091e8cf4:/pyats# pip list
Package    Version
---------- -------
pip        21.1.3
setuptools 57.0.0
wheel      0.36.2
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@34db091e8cf4:/pyats#

CodePudding user response:

When you docker run the image, you'll note the following output:

[Entrypoint] Starting pyATS Docker Image ...
[Entrypoint] Workspace Directory: /pyats
[Entrypoint] Activating workspace

There is some sort of initialization script that is activating the workspace (probably a Python virtual environment).

When you docker exec into the container, you're just starting a shell, without any initialization. You need to run whatever initialization steps are performed when the container starts.


If you docker inspect the image, you can see that the ENTRYPOINT is set to /bin/tini -- /entrypoint.sh, and if you take a look at /entrypoint.sh, you find this, which includes:

echo "[Entrypoint] Activating workspace"
source ${WORKSPACE}/bin/activate

(Where $WORKSPACE is an environment variable that will already be set in your shell.)

  • Related