02- commands chapter - Basic Commands frequently used commands

Basic commands

docker start and stop

 Start docker

systemctl start docker

Stop docker

systemctl stop docker

Restart docker

systemctl restart docker

View docker Status:

systemctl status docker

boot:

systemctl enable docker

View docker summary information:

docker info

View docker help documentation

docker --help

 

Commonly used commands:

1. View Mirror

docker images

REPOSITORY: image name

TAG: image tag

IMAGE ID: ID mirroring

CREATED: Creation Date mirrored (not the acquisition date of the mirror)

SIZE: image size

These images are the presence of host Docker / var / lib / directory under docker.

2. Search Mirror

If you need to find the image you want from the network, you can search by the following command.

docker search image name

NAME: warehouse Name

DESCRIPTION: Mirror Description

STARS: user evaluation, a mirror of the reaction popularity

OFFICIAL: Are official

AUTOMATED: automatically build, indicating that the mirror automatically build process created by the Docker Hub

3. Pull the mirror: the mirror is pulled from a central warehouse to the local download mirror

docker pull image name

For example, I want to download centos7 Mirror

docker pull centos:7

4. Remove the mirror: Mirror mirror image ID Delete

Mirror ID docker rmi

Delete all mirrors

docker rmi `docker images -q`  

 

Create and launch container

Create a custom container Parameters:

Create a container command: docker run

-i: indicates the operating container

-t: a rear container starts will enter its command. After the addition of these two parameters, the vessel will be able to create log into. That is assigned a pseudo-terminal.

--name: container name is created.

-v: represents a directory mapping relationship (the former is a home directory, which is mapped to a directory on the host), a plurality of a plurality of directories or files do -v mapping. Note: It is the directory for mapping, making changes on the host, and then to share the container.

-d: run behind the -d parameter will create a guardian of the container running in the background (this will not automatically logged container after container is created, if only to add -it two parameters, it will automatically create back into the container) .

-p: mapping the port, the former is a host port, which is mapped in the port of the container, may be used to make a plurality of port mapping a plurality -p.

(1) create an interactive container

docker run -it --name=mycentos centos:7 /bin/bash

 

Exit the current container

exit

(2) create a container-type guard

docker run -di --name=mycentos2 centos:7

Into the container

docker exec -it mycentos2 /bin/bash

 

Stop and start the container

Stop the container:

docker stop the container name (or the container ID)

Start container:

docker start container name (or container ID)

 

File copy

You can use the cp command if we need to copy the file into the container

File or directory name docker cp container to be copied: a container directory

Files can also be copied from the container

docker cp container name: container directories need to copy the file directory

 

Mount directory

When we can create a container, the container directory in the directory are mapped host, so that we can modify the host file to a directory in order to influence the container.

Create a container add -v parameter back to the host directory container, for example:

docker run -di -v /usr/local/myhtml:/usr/local/myhtml  --name=mycentos3 centos:7

If you share a multi-level directory, insufficient permissions prompt may appear.

This is because the security module selinux centos7 authority of the ban, and we need to add parameters --privileged = true to solve the problem do not have permission to mount the directory.

 

View container IP address

We can see the container with the following command line various data

docker inspect the container (Container ID)

You can also perform the following command to direct output direct IP address

docker inspect --format = '{{. NetworkSettings.IPAddress}}' container (Container ID)

 

Delete container

Removes the specified container:

Name docker rm container (container ID)

 

Guess you like

Origin www.cnblogs.com/itmu89/p/11846042.html