If you want to get into container and look around, you can use:
Docker container exec
To run against a running container. And to does that, we need to know the id/name of the running container.
To get id/name of the container, we can do:
Ls
For example, the name of the container is called:elegant_noether.
du -mh
and ' DU-MH ' would print out the size of each folder:
$ docker Container exec Elegant_noetherdu-mh16k./error/include220k./error44k./Build8.0K./htdocs892k./include72k./conf/extra72k./conf/original/extra96k./conf/original268k./conf260k./icons/Small1.3M./icons20k./cgi-bin4.5M./Modules8.0K./logs1.2M./bin8.4M.
Running commands is cool, but we can also attach a shell to those containers and browse them just like they were a full op Erating System.
-i
-t
exec
The and flags can is passed to the command to keep a interactive shell open, and you can specify the She ll you want to attach after the container ID. Here we'll attach a standard Bash shell.
Docket Container exec-it Elegant_noether/bin/bash
We ' re in! From the perspective of the terminal window we ' re just navigating a normal Unix system, so any commands we type would run I Nside of that system. Try typing that same command we just ran with from exec
inside the container.
Now to check the size of each folder, we can just do:
du -mh
$ docker Container exec-it elegant_noether/bin/Bash[email protected]:/usr/local/apache2#du-mh16k./error/include220k./error44k./Build8.0K./htdocs892k./include72k./conf/extra72k./conf/original/extra96k./conf/original268k./conf260k./icons/Small1.3M./icons20k./cgi-bin4.5M./Modules8.0K./logs1.2M./bin8.4M.
Another thing we can do once we ' re in a container's shell is install new programs, or packages, which aren ' t part of the BA SE image. Let's install the package fortunes
.
Install -y fortunes
The package is installed in
/usr/games/fortune
It ' s kind /usr/games/
fortune
of annoying to has to type before the command, so let's update the PATH
environment variable in th e container So, we don ' t has to type all of the that anymore.
Path= $PATH:/usr/games/
Now we can export path:
Export PATH
After then we can just type ' fortune ' to start the game
[Docker] Accessing a Container