[Docker] Accessing a Container

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.