Learn Docker:4 yourself. Get started with Docker working mode

Source: Internet
Author: User

The previous chapter has 2 questions in the study:

    1. How do I save our changes in the container?
    2. If Apt-get is not installed, how do I install the software in Docker?
About container issues created by run

For the first question, the original is executed each time (when the non-root user needs to add sudo before the command)

-i-t docker/whalesay /bin/bash

will create a new container, which should be clear. However, when exiting, the container that was created is not deleted or exists with the system. Pass

sudo-a

can be viewed.

In the list, the first column CONTAINER ID is the ID of the image, and the first one in the table, which is ID 7409de9e92f0, is the one that was created in my previous article with Vim installed.
Image is the image that is used to create the container.
COMMAND is the last action performed on the Mirror.
CREATED is the creation time.
status is the current state of the container.
PORTS
NAMES is a unique name for the container. The default is that Docker executes the run to create the container that is named. If we want to specify a name, you need to use the name option

run--name test docker/whalesay /bin/bash

The container name that you create is test.

Just like the container with ID cc8a23b1d624 above.
An exception occurs when we create a container named Test again.

This also indicates that the name of the Docker container is unique.
However, the above tip prompts you to conflict with the ID "cc8a23b1d624a63ec2147b7f1a6f965852df4a20e3ca1f50bbb08d3dabaccf0b" container when creating a container named Test. This ID is not a cc8a23b1d624 of the ID of the PS-A list test. So where does this long ID come from?
This involves how the container created by the Docker Run command is saved locally. The containers created by default Docker save the early directories:

/var/lib/docker/

Viewing this directory requires permissions, so we may need to switch to the root user.

Here you can see the id "cc8a23b1d624a63ec2147b7f1a6f965852df4a20e3ca1f50bbb08d3dabaccf0b" above. This is where the Docker creation container is saved.
Go inside and look at the description file that corresponds to the directory that is saved in the container.

Pass

sudo docker inspect ID

You can view container configuration details,

At this point, a JSON-formatted message is returned.

Jane says Docker working mode

Why these files are generated is related to Docker's working mode.
When Docker creates a container, Docker loads the read-only image we specified and adds a read-write layer to it (copying a copy of the Mirror directory to the/var/lib/docker/aufs/mnt ID directory, which is the long ID we see above. If we use Chroot to enter this directory, we will find that the directory structure is the same as the directory inside the container). If a running container modifies an existing file that already exists, the file will be copied from the read-only layer below it to the read-write layer, the read-only version of the file still exists, but it is hidden by a copy of the file in the read-write layer, and when the Docker container is deleted and restarted through the mirror, The previous changes will be lost.
This is why, when we have run to start the container again, the previous changes are gone.

Enter the container you created earlier

Since the container we created is saved in a writable way, we should be able to enter it again. Above we already know how to list the created containers, just like our previous installation of the Vim container id–7409de9e92f0.
The ID of the container knows, now it's time to get into the container again. Before we had exited the container, we had to start it again if we wanted to enter again.

sudo docker start ID/NAME

Specify id-7409de9e92f0 later, or Name-pensive_darwin.

As you can see, the container state with ID 7409de9e92f0 becomes "Up 3 seconds".
And then we can get into the container,

sudo docker attach ID/NAME


As you can see here, we have entered the container with ID 7409de9e92f0, and as such, we can see from the dpkg command that the vim we installed last time is there.

This time first came here, although not completely solve the previous two problems, but the understanding of Docker a bit deeper, I believe the problem will always be resolved.

Learn Docker:4 yourself. Get started with Docker working mode

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.