Docker image and container command topic

developerguy 2016-03-13 13:50:00 Browse 19 Comments 0
docker ubuntu windows image host container Image view

summary: docker workflow diagram: At least three things need to be equipped to use docker container: Docker host: Docker container will be in Linux virtual host running on it. .Docker images: Similar to iso images that run on vms, but they are highly stripped down versions.

Docker workflow diagram:



At least three things are required to use a docker container:

Docker host: A Linux virtual host on which the Docker container will run. .Docker images :
Similar to iso images that run on vm virtual machines, but they are highly stripped down versions. All redundant packages or libraries already present on the docker host will be removed.
Docker containers: Snapshots of Docker images that you can start, stop, modify, or publish as another image.


Docker is an open source engine that makes it easy to create a lightweight, portable, self-sufficient container for any application. Containers that developers compile and test on laptops can be deployed in production environments in batches, including VMs (virtual machines), bare metal, OpenStack clusters and other basic application platforms.
Docker is commonly used in the following scenarios:
automated packaging and publishing of web applications;
automated testing and continuous integration, publishing;
deploying and tuning databases or other background applications in a service-oriented environment;

compiling or extending existing OpenShift or Cloud Foundry platforms from scratch to build your own PaaS environment.

1. Mirror-related commands

1. Get the image



[plain] view plain copy

View the code snippet on CODE Derive to my code snippet
sudo docker pull ubuntu:12.04 





2. List the local image



[plain] view plain copy

View the code on CODE The slice is derived from my code slice
sudo docker images 





In the listed information, you can see several fields of information. Which repository

comes from , such as
the mark of the ubuntu image, such as 14.04,
its ID number (unique), the
creation time, the
image size
, which is the image of the image. The ID uniquely identifies the mirror, notice that ubuntu:14.04 and ubuntu:trusty have the same mirror ID, indicating that they are actually the same mirror.
TAG information is used to tag different images from the same repository. For example, there are multiple mirrors in the ubuntu repository, and the release version is distinguished by TAG information, such as 10.04, 12.04, 12.10, 13.04, 14.04, etc. For example the following command specifies to use the image ubuntu:14.04 to start a container.

3. Create an image



Method 1:



[plain] view plain copy

View the code slice on CODE Derived to my code slice
docker commit 
Method 2:



[plain] view plain copy

View the code slice derived from CODE to my code slice
dockerFile 


4. Remove the local image

[plain] view plain copy

View the code slice derived from CODE to my code slice
You can use the docker rmi command. Note that the docker rm command removes the container. 
*Note: Before deleting the image, use docker rm to delete all containers that depend on this image.

5. Save and load the image
Save the image
If you want to export the image to a local file, you can use the docker save command.



6. Load the image

You can use docker load to import from the exported local file to the local image library, for example

[plain] view plain copy

to view the code slice on CODE derived from my code slice
sudo docker load --input ubuntu_14.04 .tar 
or

[plain] view plain copy

on CODE to view the snippet Derive to my snippet
$ sudo docker load < ubuntu_14.04.tar 

This will import the image along with its associated metadata information (including tags, etc.).





2. Container related commands

1. Start the container

There are two ways to start a container, one is to create a new container based on the image and start it, and the other is to restart the container in the stopped state.

Because Docker's containers are so lightweight, many times users delete and create new containers at any time. The required command is mainly docker run.
(1) Create and start

the following command to start a bash terminal, allowing the user to interact.



[plain] view plain copy

View the code snippet on CODE derived to my code snippet
sudo docker run -t -i training/sinatra /bin/bash 


where the -t option makes Docker allocate a pseudo terminal (pseudo-tty) and bind to the container's standard input, -i keeps the container's standard input open. You can also combine them and write



[plain] view plain copy

. View the code slice on CODE. Derive to my code slice
sudo docker run -ti ubuntu:14.04 /bin/bash 



. Only the specified bash application is running in the container. This feature makes Docker extremely efficient in resource utilization and is a real lightweight virtualization. If -t -i is not added, the container is exited after execution. For example, the following command outputs a "Hello World", and then terminates the container.

[plain] view plain copy

view snippet on CODE derived to my snippet
sudo docker run ubuntu:14.04 /bin/echo 'Hello world' 


This is almost indistinguishable from executing /bin/echo 'hello world' directly locally.

[plain] view plain copyView

code snippets on CODE derived to my code snippets
 


In interactive mode, the user can enter commands through the created terminal, for example



, what if you just want the container to run in the background? Then see below!

(2) When the daemon state runs more, it is necessary to let the Docker container run in the form of daemonized in the background. At this point, it can be achieved by adding the -d parameter. For example the following command will run the container in the background.




After the container is started, a unique id will be returned, and the container information can also be viewed through the docker ps command.



Then use



[plain] view plain copy

to view the code slice on CODE derived to my code slice
docker attach container name 
to enter the container interactive interface The
container name can be obtained through the following





[plain] view plain copy

to view the code slice on CODE derived to My code snippet
docker ps -a  
is entered as above:





Then enter:






When using docker run to create a container, the standard operations of Docker running in the background include:
check whether the specified image exists locally, and if it does not exist, download it from the public repository and
use Image creation and start a container
Allocate a file system and mount a read-write layer outside the read-only image layer. Bridge a virtual interface
from the bridge interface configured on the host host to the container.
Configure an IP address for the container from the address pool.
Execute user-specified After the application is
executed , the container is terminated

(3) Start the terminated container

You can use the docker start + container ID, command to directly start and run a terminated container.

First find the id of the container to start



[plain] view plain copy

View the code slice on the CODE Derived to my code slice
docker ps -a 




Exited means that it is terminated. Then use



[plain] view plain copy

to view the code snippet on CODE derived to my code snippet
docker start b3f9d3239bed  




Above I started two new containers in the background running mode



This is executed in the background running mode, so how? to enter the container again? You can use docker attack + container name

to first get the name of the running container through docker ps -a, and then



[plain] view plain copy

to view the code slice on CODE. Derived to my code slice
docker attach goofy_mclean 


is as follows:



The core of the container is the executed application, and the resources required are all necessary for the application to run. Other than that, there are no other resources. You can use ps or top in a pseudo terminal to view process information.

(4) Exit the container but keep it running

By default , if you use ctrl-d to exit the container, the container will also stop, press ctrl-p ctrl-q to exit to the host, and keep the container still running. Then enter and then Use docker attach



2. Stop the container and

enter exit or ctrl+d



3. Get container information

To get the output information of the container, you can use the docker logs command.



[plain] view plain copyView

the code snippet on CODE derived to my code snippet
docker logs container name 




4. Install a new program in the container The

next thing we need to do is to install a simple program (ping) in the container . The tutorial image we downloaded earlier is based on ubuntu, so you can use ubuntu's apt-get command to install the ping program: apt-get install -y ping.
Note: After the apt-get command is executed, the container will stop, but the changes to the container will not be lost.



5. Save changes to the container
When you make changes to a container (by running a certain command in the container), you can save the changes to the container, so that you can run the container from the latest state after saving next time. The process of saving state in docker is called committing, and it saves the difference between the old and new state, resulting in a new version. Or when finished, we use exit to exit, and now that our container has been changed by us, use the docker commit command to commit the updated copy.

First obtain the modified container ID to



save the container, which is actually saved as a new image.




Among them , -m specifies the submitted description information, which is the same as the version control tool we use; -a can specify the updated user information; then It is the ID of the container used to create the image; finally, specify the repository name and tag information of the target image. After the creation is successful, the ID information of the image will be returned.



Use docker images to see the newly created image.





After that, you can start the container with the new image




6. Delete the container

You can use docker rm to delete a container in the terminated state. For example,





if you want to delete a running container, you can add the -f parameter. Docker will send the SIGKILL signal to the container.



7. Check running containers

Use docker ps command to view a list of all running containers, and use the docker inspect command to view more detailed information about a container. Find the id of a running container and use the docker inspect command to view container information. The front part of the image id can be used, the full id is not required.



Note:

Summary of delete commands



Docker images often occupy the hard disk space unconsciously. In order to clean up redundant images, you can use the following methods:

1. Enter root privilege

sudo su

2. Stop all containers, so that the images can be deleted:

docker stop $ (docker ps -a -q)

If you want to delete all containers, add another command:

docker rm $(docker ps -a -q)

3. Check what images are currently

docker images

4. Delete images, by the id of the image Specify who to delete

docker rmi <image id>

want to delete untagged images, that is, those images whose id is <None>, you can use

docker rmi $(docker images | grep "^<none>" | awk "{print $3}" )

To delete all images,

docker rmi $(docker images -q)

http://blog.csdn.net/evankaka/article/details/49866265

oci runtime error appears when the directory linked to the host with Dockerfile

Or Firewall Detected. A firewall is blocking file Sharing between Windows and the containers

appears in the Docker Share Drive sharing host disk. What can be done on Docker for Windows when this phenomenon occurs?

This problem is possible in different Docker for Windows versions Appeared, and my current version is 1.13.0 (9861)

The next day after the problem appeared, there was another 1.13.0-Beta38 that could be updated. One

of my Windows 10 has always had a shared host drive to do Share Drive Used for Docker

Container One day, when I was testing Dockerfile, an oci runtime error occurred unexpectedly.

At this time, in docker-compose.yml, as long as the storage location of host and container are not mapped with Volume, we can continue.

Find the reason and re-check Share While trying to redesign Share Drive, an error message

appeared about the firewall blocking the share drive The error



message clearly pointed to a firewall issue

There was a lot of discussion on Github about this error message, and this should be Unique to Docker for Windows

but on different versions although the error message is the same but the cause and solution are different

https://github.com/docker/for-win/issues/114

https://github.com/docker/for-win/issues/355

And I was able to solve the problem in the end, here are some actions that people who have the same problem can try

1. Turn off the firewall

As the error message says, we should First rule out what is blocked by the firewall.

If you turn off the firewall and it works normally, please re-check whether the firewall rules set during the Docker installation, DockerSmbMount, exist



. But Github usually says that if you really turn off the firewall, it can be solved. You can only continue to close the firewall to continue to wait for the update file.



2. There is no clear sharing function in the Docker Setting of the re-shared disk drive

.

In response, if you type net share, you will still see C$ in the list.



You have to start Powershell as Administrator, type Net share c$ /delete (assuming you shared C:\ )

and then try to share in Docker



3. Reset the shared account used by Docker

. There is a "Reset Credentials" function on the Docker Shared Drive page.

I finally solved the problem in this way, but we must first create an account to Use to

open Computer Management, select New User in User to

create a common user account, such as dockershare



Go back to Shared Drives, press Reset credentials and
enter the account password you just created. Go



to Reset page and select Restart Docker. After waiting for Docker to restart, I will solve the problem here.


This problem has appeared intermittently in some Docker forks since mid-2016. On the Windows version,

I hope this article can help other friends who encounter problems

https://dotblogs.com.tw/swater111/2017/01/26/101009







This article is the original content of the Yunqi community, and may not be reproduced without permission, such as If you need to reprint, please send an email to [email protected]; if you find any suspected plagiarism in this community, please send an email to: [email protected] to report and provide relevant evidence, once verified , the community will immediately delete the allegedly infringing content.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326163928&siteId=291194637